Good find but why does it need to compare _height with contentHeight in the beginning at all? Normally what should imo happen is simply:
So just: _height = Math.min(realHeight, maxHeight)