optimized length()