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

Unified Diff: components/rappor/byte_vector_utils.cc

Issue 2156383002: Avoid some string copies in RAPPOR code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/rappor/byte_vector_utils.h ('k') | components/rappor/reports.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/rappor/byte_vector_utils.cc
diff --git a/components/rappor/byte_vector_utils.cc b/components/rappor/byte_vector_utils.cc
index e9e58b6614cbf3f21139cec1f6d59cc499f01452..03d4786cc8240fc3f7a9bdf45cf4c90c6eed79f5 100644
--- a/components/rappor/byte_vector_utils.cc
+++ b/components/rappor/byte_vector_utils.cc
@@ -22,8 +22,11 @@ base::StringPiece ByteVectorAsStringPiece(const ByteVector& lhs) {
}
// Concatenates parameters together as a string.
-std::string Concat(const ByteVector& value, char c, const std::string& data) {
- return std::string(value.begin(), value.end()) + c + data;
+std::string Concat(const ByteVector& value, char c, base::StringPiece data) {
+ std::string result(value.begin(), value.end());
+ result += c;
+ data.AppendToString(&result);
+ return result;
}
// Performs the operation: K = HMAC(K, data)
@@ -54,7 +57,7 @@ bool HMAC_Rehash(const crypto::HMAC& hmac, ByteVector* value) {
// The input "Key" is passed by initializing |hmac1| with it.
// The output "Key" is returned by initializing |out_hmac| with it.
// Returns false on an error.
-bool HMAC_DRBG_Update(const std::string& provided_data,
+bool HMAC_DRBG_Update(base::StringPiece provided_data,
const crypto::HMAC& hmac1,
ByteVector* value,
crypto::HMAC* out_hmac) {
@@ -164,7 +167,7 @@ ByteVector ByteVectorGenerator::GetWeightedRandomByteVector(
HmacByteVectorGenerator::HmacByteVectorGenerator(
size_t byte_count,
const std::string& entropy_input,
- const std::string& personalization_string)
+ base::StringPiece personalization_string)
: ByteVectorGenerator(byte_count),
hmac_(crypto::HMAC::SHA256),
value_(hmac_.DigestLength(), 0x01),
@@ -175,7 +178,8 @@ HmacByteVectorGenerator::HmacByteVectorGenerator(
// Note: We are using the 8.6.7 interpretation, where the entropy_input and
// nonce are acquired at the same time from the same source.
DCHECK_EQ(kEntropyInputSize, entropy_input.size());
- std::string seed_material(entropy_input + personalization_string);
+ std::string seed_material(entropy_input);
+ personalization_string.AppendToString(&seed_material);
// 2. Key = 0x00 00...00
crypto::HMAC hmac1(crypto::HMAC::SHA256);
if (!hmac1.Init(std::string(hmac_.DigestLength(), 0x00)))
« no previous file with comments | « components/rappor/byte_vector_utils.h ('k') | components/rappor/reports.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698