{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/10575","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/10575/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/10575/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/10575/events","html_url":"https://github.com/nodejs/node/pull/10575","id":198362614,"number":10575,"title":"buffer: improve buff.toString(encoding, start, end)","user":{"login":"JacksonTian","id":327019,"avatar_url":"https://avatars.githubusercontent.com/u/327019?v=3","gravatar_id":"","url":"https://api.github.com/users/JacksonTian","html_url":"https://github.com/JacksonTian","followers_url":"https://api.github.com/users/JacksonTian/followers","following_url":"https://api.github.com/users/JacksonTian/following{/other_user}","gists_url":"https://api.github.com/users/JacksonTian/gists{/gist_id}","starred_url":"https://api.github.com/users/JacksonTian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JacksonTian/subscriptions","organizations_url":"https://api.github.com/users/JacksonTian/orgs","repos_url":"https://api.github.com/users/JacksonTian/repos","events_url":"https://api.github.com/users/JacksonTian/events{/privacy}","received_events_url":"https://api.github.com/users/JacksonTian/received_events","type":"User","site_admin":false},"labels":[{"id":155267414,"url":"https://api.github.com/repos/nodejs/node/labels/buffer","name":"buffer","color":"f7c6c7","default":false},{"id":326905670,"url":"https://api.github.com/repos/nodejs/node/labels/performance","name":"performance","color":"5319e7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-01-02T17:26:18Z","updated_at":"2017-01-03T17:08:24Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/10575","html_url":"https://github.com/nodejs/node/pull/10575","diff_url":"https://github.com/nodejs/node/pull/10575.diff","patch_url":"https://github.com/nodejs/node/pull/10575.patch"},"body":"When buff.toString() without parameter will call\r\nbuff.utf8Slice(0, this.length) directly. It skips the start/end\r\ncheck, even thougth the buffer length is zero.\r\n\r\nThe utf8Slice is a C++ binding method, when the buffer length is\r\nzero, the case is unexpected.\r\n\r\nAnd, the slowToString.apply(this, arguments) is slowly also,\r\nchange to slowToString.call(this, encoding, start, end).\r\n\r\n<!--\r\nThank you for your pull request. Please provide a description above and review\r\nthe requirements below.\r\n\r\nBug fixes and new features should include tests and possibly benchmarks.\r\n\r\nContributors guide: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md\r\n-->\r\n\r\n##### Checklist\r\n<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->\r\n\r\n- [x] `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes\r\n- [x] commit message follows commit guidelines\r\n\r\n##### Affected core subsystem(s)\r\n<!-- Provide affected core subsystem(s) (like doc, cluster, crypto, etc). -->\r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/270166004","html_url":"https://github.com/nodejs/node/pull/10575#issuecomment-270166004","issue_url":"https://api.github.com/repos/nodejs/node/issues/10575","id":270166004,"user":{"login":"thefourtheye","id":696611,"avatar_url":"https://avatars.githubusercontent.com/u/696611?v=3","gravatar_id":"","url":"https://api.github.com/users/thefourtheye","html_url":"https://github.com/thefourtheye","followers_url":"https://api.github.com/users/thefourtheye/followers","following_url":"https://api.github.com/users/thefourtheye/following{/other_user}","gists_url":"https://api.github.com/users/thefourtheye/gists{/gist_id}","starred_url":"https://api.github.com/users/thefourtheye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thefourtheye/subscriptions","organizations_url":"https://api.github.com/users/thefourtheye/orgs","repos_url":"https://api.github.com/users/thefourtheye/repos","events_url":"https://api.github.com/users/thefourtheye/events{/privacy}","received_events_url":"https://api.github.com/users/thefourtheye/received_events","type":"User","site_admin":false},"created_at":"2017-01-03T17:08:24Z","updated_at":"2017-01-03T17:08:24Z","body":"> If no parameters passed into toString, the C++ binding method was called, the start/end checks are skipped.\r\n\r\nWe don't have to do the start and end checks, right? Because we know that the `start` will be zero and the end will be the length of the Buffer object.\r\n\r\nBut, if your only concern is about the zero length Buffers, you might want to try special casing that, like this\r\n\r\n```js\r\n  if (this.length === 0) {\r\n    return '';\r\n  } else if (arguments.length === 0) {\r\n    result = this.utf8Slice(0, this.length);\r\n  } else {\r\n    result = slowToString.apply(this, arguments);\r\n  }\r\n```"}}
{"actor":{"display_login":"thefourtheye"}}