var s string
var slice []int
len(s)
len(slice)
Is the len()
call on string
s and slices, O(1).
From this golang official blog, I can see that the slices have the length, capacity and pointer to the underlying array. So I understood, that the len() on it may be a O(1) operation. But what about strings? Is the length of strings also internally associated with the data so that len() just looks it up and returns it?
I looked at the source builtin.go but couldn't make anything out of it.