Hello Dan Burkert, Mike Percy, Adar Dembo, I'd like you to do a code review. Please visit
http://gerrit.cloudera.org:8080/4379 to review the following change. Change subject: util: avoid redundant copies in various macros ...................................................................... util: avoid redundant copies in various macros A lot of macros have the form: #define FOO(arg) \ Foo arg_ = (arg); \ ... do something with arg_ ... Of course the purpose of the 'arg_' local is to avoid double-evaluation of the argument in the case that it's something expensive or something with a side effect. However, this pattern results in an extra copy of 'arg' in the case that it's actually a local, eg in the pattern: Foo f = ...; FOO(f); This expands out to a redundant copy 'Foo arg_ = f;'. It turns out that the solution is to make 'Foo arg_' a const reference 'const Foo& arg_'. At first, this seems wrong: references to a temporary are often bad. However, it turns out that C++ has a rule that const references to temporaries on the stack keep that temporary alive as long as the reference stays in scope. So, this is safe, and avoids an extra copy. Change-Id: I6057751d5c6790b2d350e77636b58079e2093cb7 --- M src/kudu/util/status.h M src/kudu/util/test_macros.h 2 files changed, 13 insertions(+), 13 deletions(-) git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/79/4379/1 -- To view, visit http://gerrit.cloudera.org:8080/4379 To unsubscribe, visit http://gerrit.cloudera.org:8080/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6057751d5c6790b2d350e77636b58079e2093cb7 Gerrit-PatchSet: 1 Gerrit-Project: kudu Gerrit-Branch: master Gerrit-Owner: Todd Lipcon <t...@apache.org> Gerrit-Reviewer: Adar Dembo <a...@cloudera.com> Gerrit-Reviewer: Dan Burkert <d...@cloudera.com> Gerrit-Reviewer: Mike Percy <mpe...@apache.org>