No, you can’t avoid the test as the area containing the length, the capacity 
and the items may not have been allocated yet, as in `var s: seq[int]`. You 
can’t return the address of something which doesn’t exist.

Now, I agree that if this area has been allocated, it would be possible to 
simply return something like `s[]+16` (considering `s` as a pointer). But, then 
there is a inconsistency as some sequences of length 0 (those non allocated) 
will return nil, while others (those empty) will return a non nil value. It 
would be better to return nil in both cases.

And the problem was exactly the same when non allocated sequences and empty 
sequences were considered different. Before accessing the area containing the 
length, the capacity and the items, you had to check that the sequence was not 
nil.

To get the address of the area containing the items without checking that `s` 
is not nil, the compiler should systematically create the area containing the 
length, the capacity and the (empty) item field. I suppose it would have 
simplified some things (no need for the runtime to check for nil when doing 
operations on sequence) at the price of a possibly useless allocation.

Reply via email to