Which is faster

yes I know I can test this… but if someone knows off the top of their head :slight_smile:

If I have a PAIR (say 3:9) and I want to increment the RIGHT

which is faster?

myPair=myPair.Left:myPair.Right+1

or

myPair=myPair.Left:myPair.Right.IntegerValue+1

explicit vs implied casting?

Wouldn’t you not want to recreate the object? That would involve a call to the constructor. Maybe just this?

myPair.Right = myPair.Right.IntegerValue+1
Not sure which is faster though, so you might have to remove the IntegerValue ;p

unfortunalty I DO have to recreate it :frowning:

in reality it is

newPair=oldPair.Left:oldPair.right+1

Wont work
You cant assign to left or right except by creating the pair - they’re immutable :stuck_out_tongue:

And the second with explicit typing is probably a tad quicker (but not much over millions of iterations)

Norman… as a side note… since this is all kind of related…
I came up with a very fast method for doing a Row or Column insert (of which this question was part)
It was inspired by an idea that Tim Hare proposed…
It takes all the appropriate keys (those below insert row index) sorts them inverse
then just

dict.value(new_key)=dict.value(old_key)
dict.remove old_key

insert at row 4 in a 10,000 row grid in less then 0.1 seconds
was hoping to tweak it even faster :slight_smile:

[quote=170592:@Norman Palardy]Wont work
You cant assign to left or right except by creating the pair - they’re immutable :stuck_out_tongue:

And the second with explicit typing is probably a tad quicker (but not much over millions of iterations)[/quote]
Oops, the pair class I made for iOS IS mutable. Guess my advice only applies to that :stuck_out_tongue: