Skip to content

Store list.length in a variable #8922

@p1pchenk0

Description

@p1pchenk0

What problem does this feature solve?

Increase performance during Vue preparations. During Vue initialization process there is a function makeMap, which splits string of items into array and then create Map-like object. But during for-loop every iteration it checks list.length value, which can be stored in separate variable before running for-loop. For arrays of 40 this can improve performance

What does the proposed API look like?

    function makeMap (str, expectsLowerCase) {
        var map = Object.create(null);
        var list = str.split(',');
        var listLength = list.length;  // <--  here it is

        for (var i = 0; i < listLength; i++) {
            map[list[i]] = true;
        }
        
        return expectsLowerCase ? function (val) { return map[val.toLowerCase()] } : function (val) { return map[val] }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions