This is woefully.
Imagine a toy instruction set:
// Sets a byte of value Y at location X
SET X Y
// Returns the byte stored at location X
GET X
If we create an array and access it, what does that compile to?
byte index = 2;
byte[] bytes = new bytes[5];
bytes[1] = 12;
bytes[index] = 34;
You seem to be suggesting we would get something like the following:
// 100 is the offset of `index`, 200 is the offset of `bytes`
SET 100 2
SET (200 + 1 - 1) 12
SET (200 + index - 1) 34
Your belief, I think, is that this extra arithmetic (- 1
) would incur overhead. But that's not true, as the index of bytes
is known ahead of time. We would simply get:
SET 100 2
SET (199+ 1) 12
SET (199+ index) 34
In other words, it's trivial to just add the ordinal index to the offset immediately before the actual first element.