From: Changcheng Liu Date: Mon, 27 Jul 2020 07:27:30 +0000 (+0800) Subject: rgw: replace get_str_set with for_each_substr for performance X-Git-Tag: v16.1.0~1380^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=73bdad0552d6687064f86d2bac5cee60af73a635;p=ceph.git rgw: replace get_str_set with for_each_substr for performance 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 --- diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 2e46507955c7..db35bd683ec4 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -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("*")) { diff --git a/src/rgw/rgw_cors_swift.h b/src/rgw/rgw_cors_swift.h index 857b914a8bb6..4bb103a467d8 100644 --- a/src/rgw/rgw_cors_swift.h +++ b/src/rgw/rgw_cors_swift.h @@ -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 o, h, oc; + set o, h; list 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::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::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;