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

Unified Diff: sandbox/linux/services/broker_process_utils.cc

Issue 18337010: Avoid std::string copying in GetFileNameInWhitelist. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 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
Index: sandbox/linux/services/broker_process_utils.cc
diff --git a/sandbox/linux/services/broker_process_utils.cc b/sandbox/linux/services/broker_process_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fed02622334578e31f3b2c3925fd3cf33e38dc47
--- /dev/null
+++ b/sandbox/linux/services/broker_process_utils.cc
@@ -0,0 +1,47 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "broker_process_utils.h"
+
+#include "base/logging.h"
+
+namespace sandbox {
+
+const char* BrokerProcessUtils::Find(
jln (very slow on Chromium) 2013/07/08 22:36:51 If this is not really guaranteed async signal safe
Jorge Lucangeli Obes 2013/07/09 03:52:12 Done, but I don't understand why this would not re
+ const char* needle,
+ const std::vector<std::string>& haystack) {
+ std::vector<std::string>::const_iterator it;
+
+ for (it = haystack.begin(); it != haystack.end(); it++) {
+ if (StrCmp(needle, it->c_str()) == 0)
+ return it->c_str();
+ }
+
+ return NULL;
+}
+
+int BrokerProcessUtils::StrCmp(const char* s1, const char* s2) {
jln (very slow on Chromium) 2013/07/08 22:36:51 As mentioned, this really needs unit tests. Pleas
+ while (*s1 != '\0' && *s2 != '\0') {
+ if (*s1 < *s2)
+ return -1;
+ else if (*s1 > *s2)
+ return 1;
+
+ s1++;
+ s2++;
+ }
+
+ if (*s1 == '\0' && *s2 == '\0')
jln (very slow on Chromium) 2013/07/08 22:36:51 Style: use brackets everywhere if you use them in
Jorge Lucangeli Obes 2013/07/09 03:52:12 Done.
+ return 0;
+ else if (*s1 == '\0')
+ return -1;
+ else if (*s2 == '\0')
+ return 1;
+ else {
+ NOTREACHED();
jln (very slow on Chromium) 2013/07/08 22:36:51 This is not async signal safe. Use RAW_CHECK (in !
Jorge Lucangeli Obes 2013/07/09 03:52:12 Done.
+ return 0;
jln (very slow on Chromium) 2013/07/08 22:36:51 GCC is still dumb enough to not see this dead code
Jorge Lucangeli Obes 2013/07/09 03:52:12 Done.
+ }
+}
+
+} // namespace sandbox

Powered by Google App Engine
This is Rietveld 408576698