To do so would be meaningless, since arrays already do that.
Fun fact: Java's ArrayList RangeCheck function has had a brutally stupid misfeature for over a decade (yes, I had posted it as a bug -- ignored) which prevented its add(), set(), and get() methods from being inlined. I kid you not.
To wit: these methods all call RangeCheck, which potentially throws an exception, along these lines (here's get(i) in pseudocode):
RangeCheck(i)
if (i >= maxLength) throw exception about i
get(i)
RangeCheck(i)
return array[i]
Until recently methods which threw exceptions could not be inlined. Thus even if get(i) was inlined, you'd still have to call an uninlinable RangeCheck(i) call every time.
This was trivially fixable:
ThrowException(i)
throw exception about i
get(i)
if (i >= maxLength) ThrowException(i)
return array[i]
This has never been fixed. Recent improvements in HotSpot have rendered it moot though, as HotSpot can now inline the RangeCheck call. But for almost a decade ArrayList has been approximately 1/4 the speed it should have been for most common calls.
Fun fact: Java's ArrayList RangeCheck function has had a brutally stupid misfeature for over a decade (yes, I had posted it as a bug -- ignored) which prevented its add(), set(), and get() methods from being inlined. I kid you not.
To wit: these methods all call RangeCheck, which potentially throws an exception, along these lines (here's get(i) in pseudocode):
Until recently methods which threw exceptions could not be inlined. Thus even if get(i) was inlined, you'd still have to call an uninlinable RangeCheck(i) call every time.This was trivially fixable:
This has never been fixed. Recent improvements in HotSpot have rendered it moot though, as HotSpot can now inline the RangeCheck call. But for almost a decade ArrayList has been approximately 1/4 the speed it should have been for most common calls.