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

Unified Diff: base/linux_util.cc

Issue 2900323002: Revert of base: Avoid unnecessary allocations in base::FindThreadID. (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/linux_util.cc
diff --git a/base/linux_util.cc b/base/linux_util.cc
index a5e73b2eff2a887b825f5f0a37857cf6aeb9dce6..bf504718f06f2accdfb9656c8714a5ba6c536e9f 100644
--- a/base/linux_util.cc
+++ b/base/linux_util.cc
@@ -22,7 +22,6 @@
#include "base/process/launch.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
-#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/synchronization/lock.h"
#include "build/build_config.h"
@@ -200,24 +199,25 @@
std::string status;
if (!ReadFileToString(FilePath(buf), &status))
return -1;
- StringTokenizer tokenizer(status, "\n");
- while (tokenizer.GetNext()) {
- StringPiece value_str(tokenizer.token_piece());
- if (!value_str.starts_with("NSpid"))
- continue;
- if (ns_pid_supported)
- *ns_pid_supported = true;
- std::vector<StringPiece> split_value_str = SplitStringPiece(
- value_str, "\t", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY);
- DCHECK_GE(split_value_str.size(), 3u);
- int value;
- // The last value in the list is the PID in the namespace.
- if (StringToInt(split_value_str.back(), &value) && value == ns_tid) {
- // The second value in the list is the real PID.
- if (StringToInt(split_value_str[1], &value))
- return value;
+ StringPairs pairs;
+ SplitStringIntoKeyValuePairs(status, ':', '\n', &pairs);
+ for (const auto& pair : pairs) {
+ const std::string& key = pair.first;
+ const std::string& value_str = pair.second;
+ if (key == "NSpid") {
+ if (ns_pid_supported)
+ *ns_pid_supported = true;
+ std::vector<StringPiece> split_value_str = SplitStringPiece(
+ value_str, "\t", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY);
+ DCHECK_NE(split_value_str.size(), 0u);
+ int value;
+ // The last value in the list is the PID in the namespace.
+ if (StringToInt(split_value_str.back(), &value) && value == ns_tid) {
+ // The first value in the list is the real PID.
+ if (StringToInt(split_value_str.front(), &value))
+ return value;
+ }
}
- break;
}
}
return -1;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698