please cache the length here.

be careful, we already have the variable "l" in this function.