]> granicus.if.org Git - curl/commitdiff
cookies: when reading from a file, only remove_expired once
authorLauri Kasanen <cand@gmx.com>
Fri, 30 Mar 2018 15:33:52 +0000 (18:33 +0300)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 2 Apr 2018 08:40:32 +0000 (10:40 +0200)
This drops the cookie load time for 8k cookies from 178ms to 15ms.

Closes #2441

lib/cookie.c
lib/cookie.h
lib/http.c
lib/setopt.c

index 63deee163588642f44eef022af4f4bcf9e13e869..1f932d78c11cba5df67ba99d3fa5cdaf58770739 100644 (file)
@@ -368,6 +368,7 @@ Curl_cookie_add(struct Curl_easy *data,
 
                 struct CookieInfo *c,
                 bool httpheader, /* TRUE if HTTP header-style line */
+                bool noexpire, /* if TRUE, skip remove_expired() */
                 char *lineptr,   /* first character of the line */
                 const char *domain, /* default domain */
                 const char *path)   /* full path used when this cookie is set,
@@ -819,7 +820,8 @@ Curl_cookie_add(struct Curl_easy *data,
      the same domain and path as this */
 
   /* at first, remove expired cookies */
-  remove_expired(c);
+  if(!noexpire)
+    remove_expired(c);
 
 #ifdef USE_LIBPSL
   /* Check if the domain is a Public Suffix and if yes, ignore the cookie.
@@ -1026,9 +1028,10 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
       while(*lineptr && ISBLANK(*lineptr))
         lineptr++;
 
-      Curl_cookie_add(data, c, headerline, lineptr, NULL, NULL);
+      Curl_cookie_add(data, c, headerline, TRUE, lineptr, NULL, NULL);
     }
     free(line); /* free the line buffer */
+    remove_expired(c); /* run this once, not on every cookie */
 
     if(fromfile)
       fclose(fp);
index cb50b71c6a9f6f4f60a9bd3a827d38397cb6684b..5342d528c2f20d8481bae13fd5a9e2ab13e791bd 100644 (file)
@@ -80,7 +80,8 @@ struct Curl_easy;
  */
 
 struct Cookie *Curl_cookie_add(struct Curl_easy *data,
-                               struct CookieInfo *, bool header, char *lineptr,
+                               struct CookieInfo *, bool header, bool noexpiry,
+                               char *lineptr,
                                const char *domain, const char *path);
 
 struct Cookie *Curl_cookie_getlist(struct CookieInfo *, const char *,
index 29dcf656204e5f973b201df185d47710b1bd9c00..674e49665678f05f02bf1274dc7fb69f87d40aef 100644 (file)
@@ -3734,7 +3734,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
       Curl_share_lock(data, CURL_LOCK_DATA_COOKIE,
                       CURL_LOCK_ACCESS_SINGLE);
       Curl_cookie_add(data,
-                      data->cookies, TRUE, k->p + 11,
+                      data->cookies, TRUE, FALSE, k->p + 11,
                       /* If there is a custom-set Host: name, use it
                          here, or else use real peer host name. */
                       conn->allocptr.cookiehost?
index da364fa81bca2db8602e0b04fdb61fffc3a33452..b0d9e23b4bd982f71136a53eec0a313e252bce01 100644 (file)
@@ -781,11 +781,13 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option,
 
         if(checkprefix("Set-Cookie:", argptr))
           /* HTTP Header format line */
-          Curl_cookie_add(data, data->cookies, TRUE, argptr + 11, NULL, NULL);
+          Curl_cookie_add(data, data->cookies, TRUE, FALSE, argptr + 11, NULL,
+                          NULL);
 
         else
           /* Netscape format line */
-          Curl_cookie_add(data, data->cookies, FALSE, argptr, NULL, NULL);
+          Curl_cookie_add(data, data->cookies, FALSE, FALSE, argptr, NULL,
+                          NULL);
 
         Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
         free(argptr);