• tfarina's avatar
    base: Use a simple tricky to remove a temporary variable in MD5DigestToBase16. · fb9d8f3c
    tfarina authored
    With this tricky we don't need this strange 'j' variable laying around
    outside the loop, even better, since that variable is not even used
    outside of the for loop.
    
    The iteration using this tricky goes like the following:
    
    The old tricky using just 'i':
    For i = 0:
        0 * 2     = 0
        0 * 2 + 1 = 1
    
    For i = 1:
        1 * 2     = 2
        1 * 2 + 1 = 3
    
    For i = 2:
        2 * 2     = 4
        2 * 2 + 1 = 5
    
    The new tricky using 'j':
    For i = 0:
        j = 0
        0     = 0
        0 + 1 = 1
    
    For i = 1:
        j = 2
        2     = 2
        2 + 1 = 3
    
    For i = 2:
        j = 4
        4     = 4
        4 + 1 = 5
    
    So the new code does the same thing as the old but with the advantage of
    not having to use a temporary variable outside the loop.
    
    And the tricky with 'j' has also the benefit of avoid a multiplication and the rules of operator precedence.
    
    BUG=None
    TEST=base_unittests --gtest_filter=MD5*
    R=thestig@chromium.org
    
    Review URL: https://codereview.chromium.org/1065733005
    
    Cr-Commit-Position: refs/heads/master@{#324171}
    fb9d8f3c
md5.cc 9.2 KB