diff options
author | Loo Rong Jie <loorongjie@gmail.com> | 2018-02-05 08:36:58 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-02-05 08:38:28 -0800 |
commit | 8d5deed073025f80f6651a2afedb333494e0c519 (patch) | |
tree | 8fe1f2b72897c97262253746070506410012858b /src/tools/launcher | |
parent | 441dc763923a16d59b548ef7cdf97de79fd98932 (diff) |
Optimize GetRandomStr
Closes #4489.
PiperOrigin-RevId: 184532916
Diffstat (limited to 'src/tools/launcher')
-rw-r--r-- | src/tools/launcher/util/launcher_util.cc | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/tools/launcher/util/launcher_util.cc b/src/tools/launcher/util/launcher_util.cc index 83aa3f8988..453b9f0f6a 100644 --- a/src/tools/launcher/util/launcher_util.cc +++ b/src/tools/launcher/util/launcher_util.cc @@ -162,13 +162,14 @@ bool SetEnv(const string& env_name, const string& value) { string GetRandomStr(size_t len) { static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - ostringstream rand_str; + string rand_str; + rand_str.reserve(len); unsigned int x; for (size_t i = 0; i < len; i++) { rand_s(&x); - rand_str << alphabet[x % strlen(alphabet)]; + rand_str += alphabet[x % strlen(alphabet)]; } - return rand_str.str(); + return rand_str; } bool NormalizePath(const string& path, string* result) { |