{"action":"created","comment":{"url":"https://api.github.com/repos/nodejs/node/pulls/comments/51473469","id":51473469,"diff_hunk":"@@ -198,63 +211,179 @@ QueryString.stringify = QueryString.encode = function(obj, sep, eq, options) {\n   return '';\n };\n \n-// Parse a key=val string.\n+// Parse a key/val string.\n QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {\n   sep = sep || '&';\n   eq = eq || '=';\n-  const eqLen = eq.length;\n-  var obj = {};\n+\n+  const obj = {};\n \n   if (typeof qs !== 'string' || qs.length === 0) {\n     return obj;\n   }\n \n+  if (typeof sep !== 'string')\n+    sep += '';\n+\n+  const eqLen = eq.length;\n+  const sepLen = sep.length;\n+\n   var maxKeys = 1000;\n   if (options && typeof options.maxKeys === 'number') {\n     maxKeys = options.maxKeys;\n   }\n \n-  // maxKeys <= 0 means that we should not limit keys count\n-  if (maxKeys > 0) {\n-    qs = qs.split(sep, maxKeys);\n-  } else {\n-    qs = qs.split(sep);\n-  }\n-\n-  var len = qs.length;\n+  var pairs = Infinity;\n+  if (maxKeys > 0)\n+    pairs = maxKeys;\n \n   var decode = QueryString.unescape;\n   if (options && typeof options.decodeURIComponent === 'function') {\n     decode = options.decodeURIComponent;\n   }\n-\n-  var keys = [];\n-  for (var i = 0; i < len; ++i) {\n-    // replacePlus() is used instead of a regexp because it is ~15-30% faster\n-    // with v8 4.7\n-    const x = replacePlus(qs[i]);\n-    const idx = x.indexOf(eq);\n-    var k, v;\n-\n-    if (idx >= 0) {\n-      k = decodeStr(x.substring(0, idx), decode);\n-      v = decodeStr(x.substring(idx + eqLen), decode);\n+  const customDecode = (decode !== qsUnescape);\n+\n+  const keys = [];\n+  var lastPos = 0;\n+  var sepIdx = 0;\n+  var eqIdx = 0;\n+  var key = '';\n+  var value = '';\n+  var keyEncoded = customDecode;\n+  var valEncoded = customDecode;\n+  var encodeCheck = 0;\n+  for (var i = 0; i < qs.length; ++i) {\n+    const code = qs.charCodeAt(i);\n+\n+    // Try matching key/value pair separator (e.g. '&')\n+    if (code === sep.charCodeAt(sepIdx)) {\n+      if (++sepIdx === sepLen) {\n+        // Key/value pair separator match!\n+        const end = i - sepIdx + 1;\n+        if (eqIdx < eqLen) {\n+          // If we didn't find the key/value separator, treat the substring as\n+          // part of the key instead of the value\n+          if (lastPos < end)\n+            key += qs.slice(lastPos, end);\n+        } else if (lastPos < end)\n+          value += qs.slice(lastPos, end);\n+        if (keyEncoded)\n+          key = decodeStr(key, decode);\n+        if (valEncoded)\n+          value = decodeStr(value, decode);\n+        // Use a key array lookup instead of using hasOwnProperty(), which is\n+        // slower\n+        if (keys.indexOf(key) === -1) {","path":"lib/querystring.js","position":190,"original_position":190,"commit_id":"ed61c279782697994963f57a6d273d035310e6e4","original_commit_id":"ed61c279782697994963f57a6d273d035310e6e4","user":{"login":"bnoordhuis","id":275871,"avatar_url":"https://avatars.githubusercontent.com/u/275871?v=3","gravatar_id":"","url":"https://api.github.com/users/bnoordhuis","html_url":"https://github.com/bnoordhuis","followers_url":"https://api.github.com/users/bnoordhuis/followers","following_url":"https://api.github.com/users/bnoordhuis/following{/other_user}","gists_url":"https://api.github.com/users/bnoordhuis/gists{/gist_id}","starred_url":"https://api.github.com/users/bnoordhuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnoordhuis/subscriptions","organizations_url":"https://api.github.com/users/bnoordhuis/orgs","repos_url":"https://api.github.com/users/bnoordhuis/repos","events_url":"https://api.github.com/users/bnoordhuis/events{/privacy}","received_events_url":"https://api.github.com/users/bnoordhuis/received_events","type":"User","site_admin":false},"body":"This is O(n^2) relative to the total number of keys, isn't it?  I suppose `maxKeys` mitigates this to some extent?","created_at":"2016-02-01T20:12:47Z","updated_at":"2016-02-01T20:12:47Z","html_url":"https://github.com/nodejs/node/pull/5012#discussion_r51473469","pull_request_url":"https://api.github.com/repos/nodejs/node/pulls/5012","_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments/51473469"},"html":{"href":"https://github.com/nodejs/node/pull/5012#discussion_r51473469"},"pull_request":{"href":"https://api.github.com/repos/nodejs/node/pulls/5012"}}},"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/5012","id":57778570,"html_url":"https://github.com/nodejs/node/pull/5012","diff_url":"https://github.com/nodejs/node/pull/5012.diff","patch_url":"https://github.com/nodejs/node/pull/5012.patch","issue_url":"https://api.github.com/repos/nodejs/node/issues/5012","number":5012,"state":"open","locked":false,"title":"querystring: improve parse() and escape() performance","user":{"login":"mscdex","id":54666,"avatar_url":"https://avatars.githubusercontent.com/u/54666?v=3","gravatar_id":"","url":"https://api.github.com/users/mscdex","html_url":"https://github.com/mscdex","followers_url":"https://api.github.com/users/mscdex/followers","following_url":"https://api.github.com/users/mscdex/following{/other_user}","gists_url":"https://api.github.com/users/mscdex/gists{/gist_id}","starred_url":"https://api.github.com/users/mscdex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mscdex/subscriptions","organizations_url":"https://api.github.com/users/mscdex/orgs","repos_url":"https://api.github.com/users/mscdex/repos","events_url":"https://api.github.com/users/mscdex/events{/privacy}","received_events_url":"https://api.github.com/users/mscdex/received_events","type":"User","site_admin":false},"body":"`parse()` performance is improved by ~20-200% with the various querystring-parse benchmarks.\r\n\r\nSome optimization strategies used include:\r\n* Combining multiple searches (for '&', '=', and '+') on the same\r\n   string into a single loop\r\n* Avoiding `string.split()`\r\n* Minimizing creation of temporary strings\r\n* Avoiding string decoding if no encoded bytes were found and the\r\n   default string decoder is being used\r\n\r\n`escape()` performance is improved a bit, up to ~15% with the various querystring-stringify benchmarks by reducing the number of string concatenations and avoiding a potential deopt if the input string ends on an incomplete multibyte character.\r\n\r\nAlso, a constant deopt in `unescapeBuffer()` is avoided by checking the index (to make sure it is not out of bounds) passed to `charCodeAt()`","created_at":"2016-01-31T20:08:01Z","updated_at":"2016-02-01T20:12:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b93307bf2dd5d2327969d2565682ea738ae60c2e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nodejs/node/pulls/5012/commits","review_comments_url":"https://api.github.com/repos/nodejs/node/pulls/5012/comments","review_comment_url":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodejs/node/issues/5012/comments","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/ed61c279782697994963f57a6d273d035310e6e4","head":{"label":"mscdex:perf-querystring","ref":"perf-querystring","sha":"ed61c279782697994963f57a6d273d035310e6e4","user":{"login":"mscdex","id":54666,"avatar_url":"https://avatars.githubusercontent.com/u/54666?v=3","gravatar_id":"","url":"https://api.github.com/users/mscdex","html_url":"https://github.com/mscdex","followers_url":"https://api.github.com/users/mscdex/followers","following_url":"https://api.github.com/users/mscdex/following{/other_user}","gists_url":"https://api.github.com/users/mscdex/gists{/gist_id}","starred_url":"https://api.github.com/users/mscdex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mscdex/subscriptions","organizations_url":"https://api.github.com/users/mscdex/orgs","repos_url":"https://api.github.com/users/mscdex/repos","events_url":"https://api.github.com/users/mscdex/events{/privacy}","received_events_url":"https://api.github.com/users/mscdex/received_events","type":"User","site_admin":false},"repo":{"id":29220048,"name":"io.js","full_name":"mscdex/io.js","owner":{"login":"mscdex","id":54666,"avatar_url":"https://avatars.githubusercontent.com/u/54666?v=3","gravatar_id":"","url":"https://api.github.com/users/mscdex","html_url":"https://github.com/mscdex","followers_url":"https://api.github.com/users/mscdex/followers","following_url":"https://api.github.com/users/mscdex/following{/other_user}","gists_url":"https://api.github.com/users/mscdex/gists{/gist_id}","starred_url":"https://api.github.com/users/mscdex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mscdex/subscriptions","organizations_url":"https://api.github.com/users/mscdex/orgs","repos_url":"https://api.github.com/users/mscdex/repos","events_url":"https://api.github.com/users/mscdex/events{/privacy}","received_events_url":"https://api.github.com/users/mscdex/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mscdex/io.js","description":"A spork of Node.js with an open governance model","fork":true,"url":"https://api.github.com/repos/mscdex/io.js","forks_url":"https://api.github.com/repos/mscdex/io.js/forks","keys_url":"https://api.github.com/repos/mscdex/io.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mscdex/io.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mscdex/io.js/teams","hooks_url":"https://api.github.com/repos/mscdex/io.js/hooks","issue_events_url":"https://api.github.com/repos/mscdex/io.js/issues/events{/number}","events_url":"https://api.github.com/repos/mscdex/io.js/events","assignees_url":"https://api.github.com/repos/mscdex/io.js/assignees{/user}","branches_url":"https://api.github.com/repos/mscdex/io.js/branches{/branch}","tags_url":"https://api.github.com/repos/mscdex/io.js/tags","blobs_url":"https://api.github.com/repos/mscdex/io.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mscdex/io.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mscdex/io.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/mscdex/io.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mscdex/io.js/statuses/{sha}","languages_url":"https://api.github.com/repos/mscdex/io.js/languages","stargazers_url":"https://api.github.com/repos/mscdex/io.js/stargazers","contributors_url":"https://api.github.com/repos/mscdex/io.js/contributors","subscribers_url":"https://api.github.com/repos/mscdex/io.js/subscribers","subscription_url":"https://api.github.com/repos/mscdex/io.js/subscription","commits_url":"https://api.github.com/repos/mscdex/io.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/mscdex/io.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/mscdex/io.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/mscdex/io.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/mscdex/io.js/contents/{+path}","compare_url":"https://api.github.com/repos/mscdex/io.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mscdex/io.js/merges","archive_url":"https://api.github.com/repos/mscdex/io.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mscdex/io.js/downloads","issues_url":"https://api.github.com/repos/mscdex/io.js/issues{/number}","pulls_url":"https://api.github.com/repos/mscdex/io.js/pulls{/number}","milestones_url":"https://api.github.com/repos/mscdex/io.js/milestones{/number}","notifications_url":"https://api.github.com/repos/mscdex/io.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mscdex/io.js/labels{/name}","releases_url":"https://api.github.com/repos/mscdex/io.js/releases{/id}","deployments_url":"https://api.github.com/repos/mscdex/io.js/deployments","created_at":"2015-01-14T01:01:23Z","updated_at":"2015-03-16T03:15:44Z","pushed_at":"2016-02-01T18:26:53Z","git_url":"git://github.com/mscdex/io.js.git","ssh_url":"git@github.com:mscdex/io.js.git","clone_url":"https://github.com/mscdex/io.js.git","svn_url":"https://github.com/mscdex/io.js","homepage":"","size":168493,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"js-dns-resolver"}},"base":{"label":"nodejs:master","ref":"master","sha":"1684957ff5a9e5d661a07fee7de29aaa7bc3bc34","user":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"repo":{"id":27193779,"name":"node","full_name":"nodejs/node","owner":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nodejs/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":false,"url":"https://api.github.com/repos/nodejs/node","forks_url":"https://api.github.com/repos/nodejs/node/forks","keys_url":"https://api.github.com/repos/nodejs/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/node/teams","hooks_url":"https://api.github.com/repos/nodejs/node/hooks","issue_events_url":"https://api.github.com/repos/nodejs/node/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/node/events","assignees_url":"https://api.github.com/repos/nodejs/node/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/node/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/node/tags","blobs_url":"https://api.github.com/repos/nodejs/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/node/languages","stargazers_url":"https://api.github.com/repos/nodejs/node/stargazers","contributors_url":"https://api.github.com/repos/nodejs/node/contributors","subscribers_url":"https://api.github.com/repos/nodejs/node/subscribers","subscription_url":"https://api.github.com/repos/nodejs/node/subscription","commits_url":"https://api.github.com/repos/nodejs/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/node/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/node/merges","archive_url":"https://api.github.com/repos/nodejs/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/node/downloads","issues_url":"https://api.github.com/repos/nodejs/node/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/node/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/node/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/node/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/node/releases{/id}","deployments_url":"https://api.github.com/repos/nodejs/node/deployments","created_at":"2014-11-26T19:57:11Z","updated_at":"2016-02-01T19:29:36Z","pushed_at":"2016-02-01T19:47:17Z","git_url":"git://github.com/nodejs/node.git","ssh_url":"git@github.com:nodejs/node.git","clone_url":"https://github.com/nodejs/node.git","svn_url":"https://github.com/nodejs/node","homepage":"https://nodejs.org","size":206303,"stargazers_count":19859,"watchers_count":19859,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2434,"mirror_url":null,"open_issues_count":719,"forks":2434,"open_issues":719,"watchers":19859,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/5012"},"html":{"href":"https://github.com/nodejs/node/pull/5012"},"issue":{"href":"https://api.github.com/repos/nodejs/node/issues/5012"},"comments":{"href":"https://api.github.com/repos/nodejs/node/issues/5012/comments"},"review_comments":{"href":"https://api.github.com/repos/nodejs/node/pulls/5012/comments"},"review_comment":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodejs/node/pulls/5012/commits"},"statuses":{"href":"https://api.github.com/repos/nodejs/node/statuses/ed61c279782697994963f57a6d273d035310e6e4"}}}}