]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: replace get_str_set with for_each_substr for performance
authorChangcheng Liu <changcheng.liu@aliyun.com>
Mon, 27 Jul 2020 07:27:30 +0000 (15:27 +0800)
committerChangcheng Liu <changcheng.liu@aliyun.com>
Tue, 28 Jul 2020 02:48:54 +0000 (10:48 +0800)
There're some redundant allocation/copy here, e.g. construct temporary
strings. Use for_each_substr based on string_view to remove redundant
copy.

Signed-off-by: Changcheng Liu <changcheng.liu@aliyun.com>
src/common/ceph_context.cc
src/rgw/rgw_cors_swift.h

index 2e46507955c7bcc63711698c0e28c6fb3267b870..db35bd683ec4ce87b4989b8c1f777f46f0c7eafc 100644 (file)
@@ -386,9 +386,14 @@ public:
     if (changed.count(
          "enable_experimental_unrecoverable_data_corrupting_features")) {
       std::lock_guard lg(cct->_feature_lock);
-      get_str_set(
-       conf->enable_experimental_unrecoverable_data_corrupting_features,
-       cct->_experimental_features);
+
+      cct->_experimental_features.clear();
+      auto add_experimental_feature = [this] (auto feature) {
+        cct->_experimental_features.emplace(std::string{feature});
+      };
+      for_each_substr(conf->enable_experimental_unrecoverable_data_corrupting_features,
+          ";,= \t", add_experimental_feature);
+
       if (getenv("CEPH_DEV") == NULL) {
         if (!cct->_experimental_features.empty()) {
           if (cct->_experimental_features.count("*")) {
index 857b914a8bb6414de899d6931a34bd483af30e2e..4bb103a467d8200f36463fd4498c8554972e41ad 100644 (file)
@@ -31,35 +31,44 @@ class RGWCORSConfiguration_SWIFT : public RGWCORSConfiguration
     ~RGWCORSConfiguration_SWIFT() {}
     int create_update(const char *allow_origins, const char *allow_headers, 
                   const char *expose_headers, const char *max_age) {
-      set<string> o, h, oc;
+      set<string> o, h;
       list<string> e;
       unsigned long a = CORS_MAX_AGE_INVALID;
       uint8_t flags = RGW_CORS_ALL;
 
-      string ao = allow_origins;
-      get_str_set(ao, oc);
-      if (oc.empty())
+      int nr_invalid_names = 0;
+      auto add_host = [&nr_invalid_names, &o] (auto host) {
+        if (validate_name_string(host) == 0) {
+          o.emplace(std::string{host});
+        } else {
+          nr_invalid_names++;
+        }
+      };
+      for_each_substr(allow_origins, ";,= \t", add_host);
+      if (o.empty() || nr_invalid_names > 0) {
         return -EINVAL;
-      for(set<string>::iterator it = oc.begin(); it != oc.end(); ++it) {
-        string host = *it;
-        if (validate_name_string(host) != 0)
-          return -EINVAL;
-        o.insert(o.end(), host);
       }
+
       if (allow_headers) {
-        string ah = allow_headers;
-        get_str_set(ah, h);
-        for(set<string>::iterator it = h.begin();
-            it != h.end(); ++it) {
-          string s = (*it);
-          if (validate_name_string(s) != 0)
-            return -EINVAL;
+        int nr_invalid_headers = 0;
+        auto add_header = [&nr_invalid_headers, &h] (auto allow_header) {
+          if (validate_name_string(allow_header) == 0) {
+            h.emplace(std::string{allow_header});
+          } else {
+            nr_invalid_headers++;
+          }
+        };
+        for_each_substr(allow_headers, ";,= \t", add_header);
+        if (h.empty() || nr_invalid_headers > 0) {
+          return -EINVAL;
         }
       }
 
       if (expose_headers) {
-        string eh = expose_headers;
-        get_str_list(eh, e);
+        for_each_substr(expose_headers, ";,= \t",
+            [&e] (auto expose_header) {
+              e.emplace_back(std::string(expose_header));
+            });
       }
       if (max_age) {
         char *end = NULL;