{"action":"created","comment":{"url":"https://api.github.com/repos/nodejs/io.js/pulls/comments/31295997","id":31295997,"diff_hunk":"@@ -7,62 +7,219 @@ const alloc = smalloc.alloc;\n const truncate = smalloc.truncate;\n const sliceOnto = smalloc.sliceOnto;\n const kMaxLength = smalloc.kMaxLength;\n+const useOldBuffer = !!process.useOldBuffer;\n \n-exports.Buffer = Buffer;\n-exports.SlowBuffer = SlowBuffer;\n-exports.INSPECT_MAX_BYTES = 50;\n+var Buffer, SlowBuffer, NativeBuffer;\n \n \n-Buffer.poolSize = 8 * 1024;\n-var poolSize, poolOffset, allocPool;\n+// New Buffer implementation using Uint8Array. Done this way so the constructor\n+// name can remain \"Buffer\" and \"SlowBuffer\".\n \n+if (!useOldBuffer) {\n+  Buffer = function Buffer(arg) {\n+    // Common case.\n+    if (typeof arg === 'number') {\n+      // If less than zero, or NaN.\n+      if (arg < 0 || !(arg <= 0 || arg > 0))\n+        arg = 0;\n+      return allocate(arg);\n+    }\n \n-function createPool() {\n-  poolSize = Buffer.poolSize;\n-  allocPool = alloc({}, poolSize);\n-  poolOffset = 0;\n+    // Slightly less common case.\n+    if (typeof arg === 'string') {\n+      return fromString(arg, arguments[1]);\n+    }\n+\n+    // Unusual.\n+    return fromObject(arg);\n+  };\n+\n+  Buffer.prototype.__proto__ = Uint8Array.prototype;\n+  Buffer.__proto__ = Uint8Array;\n+\n+  SlowBuffer = function SlowBuffer(length) {\n+    if (length < 0)\n+      length = 0;\n+    return binding.create(length);\n+  };\n+\n+  SlowBuffer.prototype.__proto__ = Buffer.prototype;\n+  SlowBuffer.__proto__ = Buffer;\n+\n+  binding.setupBufferJS(Buffer.prototype);\n }\n-createPool();\n \n-function Buffer(arg) {\n-  if (!(this instanceof Buffer)) {\n-    // Avoid going through an ArgumentsAdaptorTrampoline in the common case.\n-    if (arguments.length > 1)\n-      return new Buffer(arg, arguments[1]);\n \n-    return new Buffer(arg);\n+function allocate(size) {\n+  if (size === 0)\n+    return binding.create(0);\n+  if (size < (Buffer.poolSize / 2)) {","path":"lib/buffer.js","position":66,"original_position":66,"commit_id":"bcd8e41674487c1b175b01c028699eb1ba41fecc","original_commit_id":"bcd8e41674487c1b175b01c028699eb1ba41fecc","user":{"login":"trevnorris","id":289174,"avatar_url":"https://avatars.githubusercontent.com/u/289174?v=3","gravatar_id":"","url":"https://api.github.com/users/trevnorris","html_url":"https://github.com/trevnorris","followers_url":"https://api.github.com/users/trevnorris/followers","following_url":"https://api.github.com/users/trevnorris/following{/other_user}","gists_url":"https://api.github.com/users/trevnorris/gists{/gist_id}","starred_url":"https://api.github.com/users/trevnorris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trevnorris/subscriptions","organizations_url":"https://api.github.com/users/trevnorris/orgs","repos_url":"https://api.github.com/users/trevnorris/repos","events_url":"https://api.github.com/users/trevnorris/events{/privacy}","received_events_url":"https://api.github.com/users/trevnorris/received_events","type":"User","site_admin":false},"body":"Did this before I realized that just because ArrayBuffers can be arbitrarily big, typed arrays can't. So it was \"technically\" possible to set the pool size greater than a bitwise operation could handle. But  that's not actually the case. So I'll change that back.","created_at":"2015-05-29T02:59:27Z","updated_at":"2015-05-29T02:59:27Z","html_url":"https://github.com/nodejs/io.js/pull/1825#discussion_r31295997","pull_request_url":"https://api.github.com/repos/nodejs/io.js/pulls/1825","_links":{"self":{"href":"https://api.github.com/repos/nodejs/io.js/pulls/comments/31295997"},"html":{"href":"https://github.com/nodejs/io.js/pull/1825#discussion_r31295997"},"pull_request":{"href":"https://api.github.com/repos/nodejs/io.js/pulls/1825"}}},"pull_request":{"url":"https://api.github.com/repos/nodejs/io.js/pulls/1825","id":36436761,"html_url":"https://github.com/nodejs/io.js/pull/1825","diff_url":"https://github.com/nodejs/io.js/pull/1825.diff","patch_url":"https://github.com/nodejs/io.js/pull/1825.patch","issue_url":"https://api.github.com/repos/nodejs/io.js/issues/1825","number":1825,"state":"open","locked":false,"title":"Buffer Use Uint8Array","user":{"login":"trevnorris","id":289174,"avatar_url":"https://avatars.githubusercontent.com/u/289174?v=3","gravatar_id":"","url":"https://api.github.com/users/trevnorris","html_url":"https://github.com/trevnorris","followers_url":"https://api.github.com/users/trevnorris/followers","following_url":"https://api.github.com/users/trevnorris/following{/other_user}","gists_url":"https://api.github.com/users/trevnorris/gists{/gist_id}","starred_url":"https://api.github.com/users/trevnorris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trevnorris/subscriptions","organizations_url":"https://api.github.com/users/trevnorris/orgs","repos_url":"https://api.github.com/users/trevnorris/repos","events_url":"https://api.github.com/users/trevnorris/events{/privacy}","received_events_url":"https://api.github.com/users/trevnorris/received_events","type":"User","site_admin":false},"body":"This is still partially incomplete. All tests are passing, but some parts still need to be hardened. The native API needs to return `MaybeLocal<>`, and `CreateFromString()` needs to check the return value to make sure the string could be written.\r\n\r\nAll existing tests are passing. A good chunk of the JS changes are whitespace related. For the conditional logic to allow `--use-old-buffer` flag.\r\n\r\nR=@bnoordhuis ","created_at":"2015-05-28T18:31:49Z","updated_at":"2015-05-29T02:59:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0415ed5f9ebd4ef53712af614357e472e9205f36","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nodejs/io.js/pulls/1825/commits","review_comments_url":"https://api.github.com/repos/nodejs/io.js/pulls/1825/comments","review_comment_url":"https://api.github.com/repos/nodejs/io.js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodejs/io.js/issues/1825/comments","statuses_url":"https://api.github.com/repos/nodejs/io.js/statuses/bcd8e41674487c1b175b01c028699eb1ba41fecc","head":{"label":"trevnorris:buffer-use-ab","ref":"buffer-use-ab","sha":"bcd8e41674487c1b175b01c028699eb1ba41fecc","user":{"login":"trevnorris","id":289174,"avatar_url":"https://avatars.githubusercontent.com/u/289174?v=3","gravatar_id":"","url":"https://api.github.com/users/trevnorris","html_url":"https://github.com/trevnorris","followers_url":"https://api.github.com/users/trevnorris/followers","following_url":"https://api.github.com/users/trevnorris/following{/other_user}","gists_url":"https://api.github.com/users/trevnorris/gists{/gist_id}","starred_url":"https://api.github.com/users/trevnorris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trevnorris/subscriptions","organizations_url":"https://api.github.com/users/trevnorris/orgs","repos_url":"https://api.github.com/users/trevnorris/repos","events_url":"https://api.github.com/users/trevnorris/events{/privacy}","received_events_url":"https://api.github.com/users/trevnorris/received_events","type":"User","site_admin":false},"repo":{"id":29560577,"name":"io.js","full_name":"trevnorris/io.js","owner":{"login":"trevnorris","id":289174,"avatar_url":"https://avatars.githubusercontent.com/u/289174?v=3","gravatar_id":"","url":"https://api.github.com/users/trevnorris","html_url":"https://github.com/trevnorris","followers_url":"https://api.github.com/users/trevnorris/followers","following_url":"https://api.github.com/users/trevnorris/following{/other_user}","gists_url":"https://api.github.com/users/trevnorris/gists{/gist_id}","starred_url":"https://api.github.com/users/trevnorris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trevnorris/subscriptions","organizations_url":"https://api.github.com/users/trevnorris/orgs","repos_url":"https://api.github.com/users/trevnorris/repos","events_url":"https://api.github.com/users/trevnorris/events{/privacy}","received_events_url":"https://api.github.com/users/trevnorris/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/trevnorris/io.js","description":"A spork of Node.js with an open governance model","fork":true,"url":"https://api.github.com/repos/trevnorris/io.js","forks_url":"https://api.github.com/repos/trevnorris/io.js/forks","keys_url":"https://api.github.com/repos/trevnorris/io.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/trevnorris/io.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/trevnorris/io.js/teams","hooks_url":"https://api.github.com/repos/trevnorris/io.js/hooks","issue_events_url":"https://api.github.com/repos/trevnorris/io.js/issues/events{/number}","events_url":"https://api.github.com/repos/trevnorris/io.js/events","assignees_url":"https://api.github.com/repos/trevnorris/io.js/assignees{/user}","branches_url":"https://api.github.com/repos/trevnorris/io.js/branches{/branch}","tags_url":"https://api.github.com/repos/trevnorris/io.js/tags","blobs_url":"https://api.github.com/repos/trevnorris/io.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/trevnorris/io.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/trevnorris/io.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/trevnorris/io.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/trevnorris/io.js/statuses/{sha}","languages_url":"https://api.github.com/repos/trevnorris/io.js/languages","stargazers_url":"https://api.github.com/repos/trevnorris/io.js/stargazers","contributors_url":"https://api.github.com/repos/trevnorris/io.js/contributors","subscribers_url":"https://api.github.com/repos/trevnorris/io.js/subscribers","subscription_url":"https://api.github.com/repos/trevnorris/io.js/subscription","commits_url":"https://api.github.com/repos/trevnorris/io.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/trevnorris/io.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/trevnorris/io.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/trevnorris/io.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/trevnorris/io.js/contents/{+path}","compare_url":"https://api.github.com/repos/trevnorris/io.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/trevnorris/io.js/merges","archive_url":"https://api.github.com/repos/trevnorris/io.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/trevnorris/io.js/downloads","issues_url":"https://api.github.com/repos/trevnorris/io.js/issues{/number}","pulls_url":"https://api.github.com/repos/trevnorris/io.js/pulls{/number}","milestones_url":"https://api.github.com/repos/trevnorris/io.js/milestones{/number}","notifications_url":"https://api.github.com/repos/trevnorris/io.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/trevnorris/io.js/labels{/name}","releases_url":"https://api.github.com/repos/trevnorris/io.js/releases{/id}","created_at":"2015-01-20T23:22:42Z","updated_at":"2015-05-08T19:24:32Z","pushed_at":"2015-05-28T19:34:26Z","git_url":"git://github.com/trevnorris/io.js.git","ssh_url":"git@github.com:trevnorris/io.js.git","clone_url":"https://github.com/trevnorris/io.js.git","svn_url":"https://github.com/trevnorris/io.js","homepage":"https://iojs.org","size":130347,"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":"v1.x"}},"base":{"label":"nodejs:next","ref":"next","sha":"70716fdd930e2b02b95c046f932cf63421bc065f","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":"io.js","full_name":"nodejs/io.js","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/io.js","description":"Node.js, but with bigger and faster version numbers","fork":false,"url":"https://api.github.com/repos/nodejs/io.js","forks_url":"https://api.github.com/repos/nodejs/io.js/forks","keys_url":"https://api.github.com/repos/nodejs/io.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/io.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/io.js/teams","hooks_url":"https://api.github.com/repos/nodejs/io.js/hooks","issue_events_url":"https://api.github.com/repos/nodejs/io.js/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/io.js/events","assignees_url":"https://api.github.com/repos/nodejs/io.js/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/io.js/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/io.js/tags","blobs_url":"https://api.github.com/repos/nodejs/io.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/io.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/io.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/io.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/io.js/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/io.js/languages","stargazers_url":"https://api.github.com/repos/nodejs/io.js/stargazers","contributors_url":"https://api.github.com/repos/nodejs/io.js/contributors","subscribers_url":"https://api.github.com/repos/nodejs/io.js/subscribers","subscription_url":"https://api.github.com/repos/nodejs/io.js/subscription","commits_url":"https://api.github.com/repos/nodejs/io.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/io.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/io.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/io.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/io.js/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/io.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/io.js/merges","archive_url":"https://api.github.com/repos/nodejs/io.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/io.js/downloads","issues_url":"https://api.github.com/repos/nodejs/io.js/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/io.js/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/io.js/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/io.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/io.js/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/io.js/releases{/id}","created_at":"2014-11-26T19:57:11Z","updated_at":"2015-05-29T02:04:56Z","pushed_at":"2015-05-29T02:32:58Z","git_url":"git://github.com/nodejs/io.js.git","ssh_url":"git@github.com:nodejs/io.js.git","clone_url":"https://github.com/nodejs/io.js.git","svn_url":"https://github.com/nodejs/io.js","homepage":"https://iojs.org","size":185046,"stargazers_count":12535,"watchers_count":12535,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":942,"mirror_url":null,"open_issues_count":285,"forks":942,"open_issues":285,"watchers":12535,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodejs/io.js/pulls/1825"},"html":{"href":"https://github.com/nodejs/io.js/pull/1825"},"issue":{"href":"https://api.github.com/repos/nodejs/io.js/issues/1825"},"comments":{"href":"https://api.github.com/repos/nodejs/io.js/issues/1825/comments"},"review_comments":{"href":"https://api.github.com/repos/nodejs/io.js/pulls/1825/comments"},"review_comment":{"href":"https://api.github.com/repos/nodejs/io.js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodejs/io.js/pulls/1825/commits"},"statuses":{"href":"https://api.github.com/repos/nodejs/io.js/statuses/bcd8e41674487c1b175b01c028699eb1ba41fecc"}}}}