From 79311d107ba25a9bae8e8f5d3efb13daafa79cd7 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Sat, 27 Aug 2016 22:54:09 +0200 Subject: [PATCH] fixed: line fragements were searched linearly instead of using binary search --- AppKit/CPTextView/CPLayoutManager.j | 33 +++++++---------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/AppKit/CPTextView/CPLayoutManager.j b/AppKit/CPTextView/CPLayoutManager.j index 6ce30bb19..8e82fd8c4 100644 --- a/AppKit/CPTextView/CPLayoutManager.j +++ b/AppKit/CPTextView/CPLayoutManager.j @@ -1063,33 +1063,16 @@ var _objectWithLocationInRange = function(aList, aLocation) var _objectsInRange = function(aList, aRange) { - var list = [], - c = aList.length, - location = aRange.location; + var firstIndex = [aList _indexOfObject:aRange.location sortedByFunction:_sortRange context:nil], + lastIndex = [aList _indexOfObject:CPMaxRange(aRange) sortedByFunction:_sortRange context:nil]; + + if (firstIndex === CPNotFound) + firstIndex = 0; - for (var i = 0; i < c; i++) - { - if (CPLocationInRange(location, aList[i]._range)) - { - list.push(aList[i]); + if (lastIndex === CPNotFound) + lastIndex = aList.length - 1; - if (CPMaxRange(aList[i]._range) <= CPMaxRange(aRange)) - location = CPMaxRange(aList[i]._range); - else - break; - } - else if (CPLocationInRange(CPMaxRange(aRange), aList[i]._range)) - { - list.push(aList[i]); - break; - } - else if (CPRangeInRange(aRange, aList[i]._range)) - { - list.push(aList[i]); - } - } - - return list; + return aList.slice(firstIndex, lastIndex + 1); } @implementation _CPLineFragment : CPObject