Index: Source/core/rendering/RenderGrid.cpp |
diff --git a/Source/core/rendering/RenderGrid.cpp b/Source/core/rendering/RenderGrid.cpp |
index d4c35e163ae01813baf517e6405cc215a7a856cc..85f9f05bb05419d0421b6447e248391abca026f9 100644 |
--- a/Source/core/rendering/RenderGrid.cpp |
+++ b/Source/core/rendering/RenderGrid.cpp |
@@ -1076,9 +1076,10 @@ PassOwnPtr<GridSpan> RenderGrid::resolveBeforeStartNamedGridLinePositionAgainstO |
{ |
// The grid line inequality needs to be strict (which doesn't match the after / end case) because |resolvedOppositePosition| |
// is already converted to an index in our grid representation (ie one was removed from the grid line to account for the side). |
- // FIXME: This could be a binary search as |gridLines| is ordered. |
- int firstLineBeforeOppositePositionIndex = gridLines.size() - 1; |
- for (; firstLineBeforeOppositePositionIndex >= 0 && gridLines[firstLineBeforeOppositePositionIndex] > resolvedOppositePosition; --firstLineBeforeOppositePositionIndex) { } |
+ size_t firstLineBeforeOppositePositionIndex = 0; |
+ const size_t* firstLineBeforeOppositePosition = std::lower_bound(gridLines.begin(), gridLines.end(), resolvedOppositePosition); |
+ if (firstLineBeforeOppositePosition != gridLines.end()) |
+ firstLineBeforeOppositePositionIndex = firstLineBeforeOppositePosition - gridLines.begin(); |
size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionIndex - position.spanPosition() + 1); |
size_t resolvedGridLinePosition = gridLines[gridLineIndex]; |
@@ -1089,9 +1090,10 @@ PassOwnPtr<GridSpan> RenderGrid::resolveBeforeStartNamedGridLinePositionAgainstO |
PassOwnPtr<GridSpan> RenderGrid::resolveAfterEndNamedGridLinePositionAgainstOppositePosition(size_t resolvedOppositePosition, const GridPosition& position, const Vector<size_t>& gridLines) const |
{ |
- // FIXME: This could be a binary search as |gridLines| is ordered. |
- size_t firstLineAfterOppositePositionIndex = 0; |
- for (; firstLineAfterOppositePositionIndex < gridLines.size() && gridLines[firstLineAfterOppositePositionIndex] <= resolvedOppositePosition; ++firstLineAfterOppositePositionIndex) { } |
+ size_t firstLineAfterOppositePositionIndex = gridLines.size() - 1; |
+ const size_t* firstLineAfterOppositePosition = std::upper_bound(gridLines.begin(), gridLines.end(), resolvedOppositePosition); |
+ if (firstLineAfterOppositePosition != gridLines.end()) |
+ firstLineAfterOppositePositionIndex = firstLineAfterOppositePosition - gridLines.begin(); |
size_t gridLineIndex = std::min(gridLines.size() - 1, firstLineAfterOppositePositionIndex + position.spanPosition() - 1); |
size_t resolvedGridLinePosition = adjustGridPositionForAfterEndSide(gridLines[gridLineIndex]); |