• Brett Wilson's avatar
    GN: Don't crash when mutating the list in a foreach. · dcba727e
    Brett Wilson authored
    Avoid a crash caused by mutation of the list being iterated over from inside
    the foreach loop. This does a full copy of the the iterated list since the
    code inside can't mutate the array via the loop variable anyway. Although
    theoretically slower, this doesn't seem to have a measurable performance
    regression in practice (we generally iterate over few large lists).
    
    Adds documentation and tests for iteration while mutating the underlying list
    variable.
    
    Bug: 818525
    Change-Id: I221fa230685b8998f5874154cad8d5c655b8006c
    Reviewed-on: https://chromium-review.googlesource.com/959228
    Commit-Queue: Brett Wilson <brettw@chromium.org>
    Reviewed-by: default avatarRoland McGrath <mcgrathr@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#544209}
    dcba727e
function_foreach_unittest.cc 2.94 KB