[SOUP] SoupNetworkSession::setAcceptLanguages should receive a const reference
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Jan 2014 17:02:24 +0000 (17:02 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Jan 2014 17:02:24 +0000 (17:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126966

Reviewed by Gustavo Noronha Silva.

Source/WebCore:

We don't really need to modify the Vector just to ignore the C
locale.

* platform/network/soup/SoupNetworkSession.cpp:
(WebCore::buildAcceptLanguages): Rework it to not modify the
passed vector to ignore the C locale when it's present.
(WebCore::SoupNetworkSession::setAcceptLanguages): Use const Vector<String>&.
* platform/network/soup/SoupNetworkSession.h:

Source/WebKit2:

* WebProcess/soup/WebProcessSoup.cpp:
(WebKit::setSoupSessionAcceptLanguage): Use const Vector<String>&.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161974 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/network/soup/SoupNetworkSession.cpp
Source/WebCore/platform/network/soup/SoupNetworkSession.h
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp

index 1d3138abfc66c676baed214a8f27c9fb56d9e146..61957eb33c22c37ef2dea4e9d9f5cf96c469818f 100644 (file)
@@ -1,3 +1,19 @@
+2014-01-14  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [SOUP] SoupNetworkSession::setAcceptLanguages should receive a const reference
+        https://bugs.webkit.org/show_bug.cgi?id=126966
+
+        Reviewed by Gustavo Noronha Silva.
+
+        We don't really need to modify the Vector just to ignore the C
+        locale.
+
+        * platform/network/soup/SoupNetworkSession.cpp:
+        (WebCore::buildAcceptLanguages): Rework it to not modify the
+        passed vector to ignore the C locale when it's present.
+        (WebCore::SoupNetworkSession::setAcceptLanguages): Use const Vector<String>&.
+        * platform/network/soup/SoupNetworkSession.h:
+
 2014-01-14  Piotr Grad  <p.grad@samsung.com>
 
         HTMLMediaElement::potentiallyPlaying can be more simple.
index 944839460a716a9bb48533da40f449d30a25ac7d..4f83796086f31a32fec3b67f39b1e614dd23cdd4 100644 (file)
@@ -228,22 +228,24 @@ void SoupNetworkSession::setupHTTPProxyFromEnvironment()
 #endif
 }
 
-static CString buildAcceptLanguages(Vector<String> languages)
+static CString buildAcceptLanguages(const Vector<String>& languages)
 {
+    size_t languagesCount = languages.size();
+
     // Ignore "C" locale.
-    size_t position = languages.find("c");
-    if (position != notFound)
-        languages.remove(position);
+    size_t cLocalePosition = languages.find("c");
+    if (cLocalePosition != notFound)
+        languagesCount--;
 
     // Fallback to "en" if the list is empty.
-    if (languages.isEmpty())
+    if (!languagesCount)
         return "en";
 
     // Calculate deltas for the quality values.
     int delta;
-    if (languages.size() < 10)
+    if (languagesCount < 10)
         delta = 10;
-    else if (languages.size() < 20)
+    else if (languagesCount < 20)
         delta = 5;
     else
         delta = 1;
@@ -251,8 +253,11 @@ static CString buildAcceptLanguages(Vector<String> languages)
     // Set quality values for each language.
     StringBuilder builder;
     for (size_t i = 0; i < languages.size(); ++i) {
+        if (i == cLocalePosition)
+            continue;
+
         if (i)
-            builder.append(", ");
+            builder.appendLiteral(", ");
 
         builder.append(languages[i]);
 
@@ -267,7 +272,7 @@ static CString buildAcceptLanguages(Vector<String> languages)
     return builder.toString().utf8();
 }
 
-void SoupNetworkSession::setAcceptLanguages(Vector<String> languages)
+void SoupNetworkSession::setAcceptLanguages(const Vector<String>& languages)
 {
     g_object_set(m_soupSession.get(), "accept-language", buildAcceptLanguages(languages).data(), nullptr);
 }
index 179d22e5d0b57cd0a09d82ccf85d8f82a43c896f..235816e4425e7f316928046d71963f915e2c346e 100644 (file)
@@ -70,7 +70,7 @@ public:
     char* httpProxy() const;
     void setupHTTPProxyFromEnvironment();
 
-    void setAcceptLanguages(Vector<String>);
+    void setAcceptLanguages(const Vector<String>&);
 
 private:
     SoupNetworkSession(SoupCookieJar*);
index b86139e255203452cdb133aa8e208cac887fd654..39efcb128c88dd82e8cd1186a68a0ddf37cd67d9 100644 (file)
@@ -1,3 +1,13 @@
+2014-01-14  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [SOUP] SoupNetworkSession::setAcceptLanguages should receive a const reference
+        https://bugs.webkit.org/show_bug.cgi?id=126966
+
+        Reviewed by Gustavo Noronha Silva.
+
+        * WebProcess/soup/WebProcessSoup.cpp:
+        (WebKit::setSoupSessionAcceptLanguage): Use const Vector<String>&.
+
 2014-01-14  Andreas Kling  <akling@apple.com>
 
         Remove deprecated DeferrableOneShotTimer constructor.
index 809abf6392ddf36904b9092f740d8b9cab323164..ab81934b7a26829d2425f34d571f8e5530ea0e11 100644 (file)
@@ -124,7 +124,7 @@ void WebProcess::platformClearResourceCaches(ResourceCachesToClear cachesToClear
     soup_cache_clear(WebCore::SoupNetworkSession::defaultSession().cache());
 }
 
-static void setSoupSessionAcceptLanguage(Vector<String> languages)
+static void setSoupSessionAcceptLanguage(const Vector<String>& languages)
 {
     WebCore::SoupNetworkSession::defaultSession().setAcceptLanguages(languages);
 }