Enable move constructors for protobufs This enables an experimental option for protobuf to generate move constructors for protos. This should make storing protobufs in containers more performant, and also should allow us to avoid some current patterns where we use ::Swap() instead of relying on more normal looking C++11-style pass-by-value with std::move().
I didn't go through and update places to take advantage of this, except for just trying it in one spot to make sure it compiles properly. I also verified in the generated code that move constructors are being generated. Change-Id: I775e770799aec44cda79e641980e91259d19e650 Reviewed-on: http://gerrit.cloudera.org:8080/6900 Tested-by: Kudu Jenkins Reviewed-by: Todd Lipcon <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/1632d16a Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/1632d16a Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/1632d16a Branch: refs/heads/master Commit: 1632d16aa599334f175b91cebb01da3bf44839c3 Parents: f1e75b7 Author: Todd Lipcon <[email protected]> Authored: Mon May 15 16:28:13 2017 -0700 Committer: Todd Lipcon <[email protected]> Committed: Fri Jun 9 20:27:54 2017 +0000 ---------------------------------------------------------------------- src/kudu/rpc/client_negotiation.cc | 2 +- thirdparty/build-definitions.sh | 8 +++++++- thirdparty/download-thirdparty.sh | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/1632d16a/src/kudu/rpc/client_negotiation.cc ---------------------------------------------------------------------- diff --git a/src/kudu/rpc/client_negotiation.cc b/src/kudu/rpc/client_negotiation.cc index 2b6b083..c1e6581 100644 --- a/src/kudu/rpc/client_negotiation.cc +++ b/src/kudu/rpc/client_negotiation.cc @@ -524,7 +524,7 @@ Status ClientNegotiation::AuthenticateByToken(faststring* recv_buf, // Send the token to the server. NegotiatePB pb; pb.set_step(NegotiatePB::TOKEN_EXCHANGE); - pb.mutable_authn_token()->Swap(authn_token_.get_ptr()); + *pb.mutable_authn_token() = std::move(*authn_token_); RETURN_NOT_OK(SendNegotiatePB(pb)); pb.Clear(); http://git-wip-us.apache.org/repos/asf/kudu/blob/1632d16a/thirdparty/build-definitions.sh ---------------------------------------------------------------------- diff --git a/thirdparty/build-definitions.sh b/thirdparty/build-definitions.sh index 4045cd0..fcbe9dc 100644 --- a/thirdparty/build-definitions.sh +++ b/thirdparty/build-definitions.sh @@ -336,10 +336,15 @@ build_gmock() { build_protobuf() { PROTOBUF_BDIR=$TP_BUILD_DIR/$PROTOBUF_NAME$MODE_SUFFIX + # Do a clean build if the patchlevel changed. + if [ "$(cd $PROTOBUF_BDIR && ls patchlevel* ||:)" != \ + "$(cd $PROTOBUF_SOURCE && ls patchlevel* ||:)" ]; then + rm -Rf $PROTOBUF_BDIR + fi mkdir -p $PROTOBUF_BDIR pushd $PROTOBUF_BDIR CFLAGS="$EXTRA_CFLAGS" \ - CXXFLAGS="$EXTRA_CXXFLAGS" \ + CXXFLAGS="$EXTRA_CXXFLAGS -DPROTO_EXPERIMENTAL_ENABLE_MOVE" \ LDFLAGS="$EXTRA_LDFLAGS" \ LIBS="$EXTRA_LIBS" \ $PROTOBUF_SOURCE/configure \ @@ -349,6 +354,7 @@ build_protobuf() { --prefix=$PREFIX fixup_libtool make -j$PARALLEL $EXTRA_MAKEFLAGS install + cp $PROTOBUF_SOURCE/patchlevel* . popd } http://git-wip-us.apache.org/repos/asf/kudu/blob/1632d16a/thirdparty/download-thirdparty.sh ---------------------------------------------------------------------- diff --git a/thirdparty/download-thirdparty.sh b/thirdparty/download-thirdparty.sh index 68950f5..7cd5b25 100755 --- a/thirdparty/download-thirdparty.sh +++ b/thirdparty/download-thirdparty.sh @@ -139,9 +139,14 @@ if [ ! -d $GPERFTOOLS_SOURCE ]; then echo fi +# We use a patchlevel=2 here to force a rebuild after changing CXXFLAGS. +# The build itself isn't smart enough to know that this requires rebuilding. +PROTOBUF_PATCHLEVEL=2 +delete_if_wrong_patchlevel $PROTOBUF_SOURCE $PROTOBUF_PATCHLEVEL if [ ! -d $PROTOBUF_SOURCE ]; then fetch_and_expand protobuf-${PROTOBUF_VERSION}.tar.gz pushd $PROTOBUF_SOURCE + touch patchlevel-$PROTOBUF_PATCHLEVEL autoreconf -fvi popd fi
