Skip to content

Commit

Permalink
Optimise CPIndexSet.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljungberg committed Mar 18, 2012
1 parent db5e5d7 commit 0d9b49d
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Foundation/CPIndexSet.j
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
{
if (!_count)
return;
[self enumerateIndexesInRange:CPMakeRange(0, CPMaxRange(_ranges[_ranges.length - 1])) options:options usingBlock:aFunction];
[self enumerateIndexesInRange:CPMakeRange(0, _CPMaxRange(_ranges[_ranges.length - 1])) options:options usingBlock:aFunction];
}

- (void)enumerateIndexesInRange:(CPRange)enumerationRange options:(CPEnumerationOptions)options usingBlock:(Function /*(int idx, @ref BOOL stop)*/)aFunction
Expand Down Expand Up @@ -528,14 +528,14 @@

if (options & CPEnumerationReverse)
{
rangeIndex = CPMaxRange(range) - 1;
rangeIndex = _CPMaxRange(range) - 1;
rangeStop = range.location - 1;
rangeIncrement = -1;
}
else
{
rangeIndex = range.location;
rangeStop = CPMaxRange(range);
rangeStop = _CPMaxRange(range);
rangeIncrement = 1;
}

Expand Down Expand Up @@ -606,7 +606,7 @@
if (lhsRangeIndexCEIL === lhsRangeIndex && lhsRangeIndexCEIL < rangeCount)
aRange = CPUnionRange(aRange, _ranges[lhsRangeIndexCEIL]);

var rhsRangeIndex = assumedPositionOfIndex(_ranges, CPMaxRange(aRange)),
var rhsRangeIndex = assumedPositionOfIndex(_ranges, _CPMaxRange(aRange)),
rhsRangeIndexFLOOR = FLOOR(rhsRangeIndex);

if (rhsRangeIndexFLOOR === rhsRangeIndex && rhsRangeIndexFLOOR >= 0)
Expand Down Expand Up @@ -709,8 +709,8 @@
// If these ranges don't start in the same place, we have to cull it.
if (aRange.location !== existingRange.location)
{
var maxRange = CPMaxRange(aRange),
existingMaxRange = CPMaxRange(existingRange);
var maxRange = _CPMaxRange(aRange),
existingMaxRange = _CPMaxRange(existingRange);

existingRange.length = aRange.location - existingRange.location;

Expand All @@ -730,14 +730,14 @@
}
}

var rhsRangeIndex = assumedPositionOfIndex(_ranges, CPMaxRange(aRange) - 1),
var rhsRangeIndex = assumedPositionOfIndex(_ranges, _CPMaxRange(aRange) - 1),
rhsRangeIndexFLOOR = FLOOR(rhsRangeIndex);

if (rhsRangeIndex === rhsRangeIndexFLOOR && rhsRangeIndexFLOOR >= 0)
{
var maxRange = CPMaxRange(aRange),
var maxRange = _CPMaxRange(aRange),
existingRange = _ranges[rhsRangeIndexFLOOR],
existingMaxRange = CPMaxRange(existingRange);
existingMaxRange = _CPMaxRange(existingRange);

if (maxRange !== existingMaxRange)
{
Expand Down Expand Up @@ -783,7 +783,7 @@
for (; i >= 0; --i)
{
var range = _ranges[i],
maximum = CPMaxRange(range);
maximum = _CPMaxRange(range);

if (anIndex >= maximum)
break;
Expand All @@ -803,7 +803,7 @@
// If it's negative, it needs to be added properly later.
else if (shifted.location < 0)
{
shifted.length = CPMaxRange(shifted);
shifted.length = _CPMaxRange(shifted);
shifted.location = 0;
}

Expand All @@ -814,8 +814,8 @@
// Shift the range, and normalize it if the result is negative.
if ((range.location += aDelta) < 0)
{
_count -= range.length - CPMaxRange(range);
range.length = CPMaxRange(range);
_count -= range.length - _CPMaxRange(range);
range.length = _CPMaxRange(range);
range.location = 0;
}
}
Expand All @@ -835,7 +835,7 @@

if ((j = i + 1) < count)
{
[_ranges removeObjectsInRange:CPMakeRange(j, count - j)];
[_ranges removeObjectsInRange:_CPMakeRange(j, count - j)];

for (j = 0, count = shifts.length; j < count; ++j)
[self addIndexesInRange:shifts[j]];
Expand Down Expand Up @@ -951,7 +951,7 @@ var positionOfIndex = function(ranges, anIndex)
if (anIndex < range.location)
high = middle - 1;

else if (anIndex >= CPMaxRange(range))
else if (anIndex >= _CPMaxRange(range))
low = middle + 1;

else
Expand Down Expand Up @@ -979,7 +979,7 @@ var assumedPositionOfIndex = function(ranges, anIndex)

if (position === positionFLOOR)
{
if (positionFLOOR - 1 >= 0 && anIndex < CPMaxRange(ranges[positionFLOOR - 1]))
if (positionFLOOR - 1 >= 0 && anIndex < _CPMaxRange(ranges[positionFLOOR - 1]))
high = middle - 1;

else if (positionFLOOR < count && anIndex >= ranges[positionFLOOR].location)
Expand All @@ -995,7 +995,7 @@ var assumedPositionOfIndex = function(ranges, anIndex)
if (anIndex < range.location)
high = middle - 1;

else if (anIndex >= CPMaxRange(range))
else if (anIndex >= _CPMaxRange(range))
low = middle + 1;

else
Expand Down

0 comments on commit 0d9b49d

Please sign in to comment.