Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Issue 1065733005: base: Use a simple tricky to remove a temporary variable in MD5DigestToBase16. (Closed)

Created:
5 years, 8 months ago by tfarina
Modified:
5 years, 8 months ago
Reviewers:
Lei Zhang
CC:
chromium-reviews, erikwright+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

base: Use a simple tricky to remove a temporary variable in MD5DigestToBase16. 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 Committed: https://crrev.com/fb9d8f3c20dc9d3024355ee989c72c4c4bf8d835 Cr-Commit-Position: refs/heads/master@{#324171}

Patch Set 1 #

Patch Set 2 : use thestig's tricky #

Unified diffs Side-by-side diffs Delta from patch set Stats (+3 lines, -4 lines) Patch
M base/md5.cc View 1 1 chunk +3 lines, -4 lines 0 comments Download

Messages

Total messages: 8 (1 generated)
tfarina
5 years, 8 months ago (2015-04-07 04:02:52 UTC) #1
Lei Zhang
If you just want to move j into the loop, you can do: for (int ...
5 years, 8 months ago (2015-04-07 21:44:05 UTC) #2
tfarina
Cool. It avoids a multiplication and operator precedence rules. Done. ptal
5 years, 8 months ago (2015-04-07 23:25:30 UTC) #3
Lei Zhang
lgtm This only works when i and j are of the same type.
5 years, 8 months ago (2015-04-07 23:28:29 UTC) #4
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1065733005/20001
5 years, 8 months ago (2015-04-07 23:55:44 UTC) #6
commit-bot: I haz the power
Committed patchset #2 (id:20001)
5 years, 8 months ago (2015-04-08 01:40:30 UTC) #7
commit-bot: I haz the power
5 years, 8 months ago (2015-04-08 01:41:16 UTC) #8
Message was sent while issue was closed.
Patchset 2 (id:??) landed as
https://crrev.com/fb9d8f3c20dc9d3024355ee989c72c4c4bf8d835
Cr-Commit-Position: refs/heads/master@{#324171}

Powered by Google App Engine
This is Rietveld 408576698