[Performance ] Added length caching

Like the tittle says, it's a very small modification that adds length caching.

This will slightly improve performance by saving a few CPU cycles to access the length property.