{"action":"created","comment":{"url":"https://api.github.com/repos/scala-js/scala-js/pulls/comments/106706998","pull_request_review_id":27646400,"id":106706998,"diff_hunk":"@@ -0,0 +1,390 @@\n+package java.util\n+\n+import java.io.{IOException, InputStream, OutputStream}\n+import java.nio.charset.StandardCharsets\n+import java.nio.{ByteBuffer, IntBuffer}\n+\n+// scalastyle:off return\n+object Base64 {\n+\n+  private type ByteTable = Array[Byte]\n+  private type IntTable = Array[Int]\n+\n+  private val chars = ('A' to 'Z') ++ ('a' to 'z') ++ ('0' to '9')\n+  private val basicEncodeTable: ByteTable = (chars ++ Seq('+', '/')).map(_.toByte).toArray\n+  private val urlSafeEncodeTable: ByteTable = (chars ++ Seq('-', '_')).map(_.toByte).toArray\n+\n+  private def decodeTable(encode: ByteTable): IntTable = {\n+    val decode: IntTable = Array.fill(256)(-1)\n+    encode.zipWithIndex.foreach{ case (b,i) => decode(b) = i}\n+    decode('=') = -2\n+    decode\n+  }\n+\n+  private val basicDecodeTable: IntTable = decodeTable(basicEncodeTable)\n+  private val urlSafeDecodeTable: IntTable = decodeTable(urlSafeEncodeTable)\n+\n+  private val mimeLineSeparators = Array[Byte]('\\r','\\n')\n+  private val mimeLineLength = 76\n+\n+  private val basicEncoder = new Encoder(basicEncodeTable)\n+  private val basicDecoder = new Decoder(basicDecodeTable, false)\n+\n+  private val mimeEncoder = new Encoder(basicEncodeTable, mimeLineLength, mimeLineSeparators)\n+  private val mimeDecoder = new Decoder(basicDecodeTable, true)\n+\n+  private val urlSafeEncoder = new Encoder(urlSafeEncodeTable)\n+  private val urlSafeDecoder = new Decoder(urlSafeDecodeTable, false)\n+\n+  // --------------------------------------------------------------------------\n+\n+  def getDecoder: Decoder = basicDecoder\n+\n+  def getEncoder: Encoder = basicEncoder\n+\n+  def getMimeDecoder: Decoder = mimeDecoder\n+\n+  def getMimeEncoder: Encoder = mimeEncoder\n+\n+  def getMimeEncoder(lineLength: Int, lineSeparator: Array[Byte]): Encoder =\n+    new Encoder(basicEncodeTable, lineLength / 4 * 4, lineSeparator)\n+\n+  def getUrlDecoder: Decoder = urlSafeDecoder\n+\n+  def getUrlEncoder: Encoder = urlSafeEncoder\n+\n+  // --------------------------------------------------------------------------\n+\n+  class Decoder private[Base64](table: IntTable, ignoreInvalid: Boolean) {\n+\n+    def decode(src: Array[Byte]): Array[Byte] = {\n+      val dst = ByteBuffer.allocate(dstMaxLength(src.length))","path":"javalib/src/main/scala/java/util/Base64.scala","position":61,"original_position":61,"commit_id":"b4e0e1e6495553446e2341a405deb7be9e7374f0","original_commit_id":"b4e0e1e6495553446e2341a405deb7be9e7374f0","user":{"login":"mvh77","id":15170363,"avatar_url":"https://avatars1.githubusercontent.com/u/15170363?v=3","gravatar_id":"","url":"https://api.github.com/users/mvh77","html_url":"https://github.com/mvh77","followers_url":"https://api.github.com/users/mvh77/followers","following_url":"https://api.github.com/users/mvh77/following{/other_user}","gists_url":"https://api.github.com/users/mvh77/gists{/gist_id}","starred_url":"https://api.github.com/users/mvh77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvh77/subscriptions","organizations_url":"https://api.github.com/users/mvh77/orgs","repos_url":"https://api.github.com/users/mvh77/repos","events_url":"https://api.github.com/users/mvh77/events{/privacy}","received_events_url":"https://api.github.com/users/mvh77/received_events","type":"User","site_admin":false},"body":"Why does manipulating a byte buffer have significant costs, isn't it just a wrapper around an array with a few ints to keep track of position, remaining etc..?\r\n\r\nI agree that for the method that takes both the src and the dst array as arguments the allocation is unnecessary, but then we'll have to do tricks to find out if the dst array is large enough to accomodate for everything, we'll have to either traverse the src twice, once for the check (as the src can contain all sorts of garbage that is legal in the case of mime), another time for the decoding. Or we can just start decoding and throw if we run out of space in the dst. Both are inefficient in a way.","created_at":"2017-03-17T17:41:54Z","updated_at":"2017-03-17T17:41:54Z","html_url":"https://github.com/scala-js/scala-js/pull/2809#discussion_r106706998","pull_request_url":"https://api.github.com/repos/scala-js/scala-js/pulls/2809","_links":{"self":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/comments/106706998"},"html":{"href":"https://github.com/scala-js/scala-js/pull/2809#discussion_r106706998"},"pull_request":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/2809"}}},"pull_request":{"url":"https://api.github.com/repos/scala-js/scala-js/pulls/2809","id":111136770,"html_url":"https://github.com/scala-js/scala-js/pull/2809","diff_url":"https://github.com/scala-js/scala-js/pull/2809.diff","patch_url":"https://github.com/scala-js/scala-js/pull/2809.patch","issue_url":"https://api.github.com/repos/scala-js/scala-js/issues/2809","number":2809,"state":"open","locked":false,"title":"Base64","user":{"login":"mvh77","id":15170363,"avatar_url":"https://avatars1.githubusercontent.com/u/15170363?v=3","gravatar_id":"","url":"https://api.github.com/users/mvh77","html_url":"https://github.com/mvh77","followers_url":"https://api.github.com/users/mvh77/followers","following_url":"https://api.github.com/users/mvh77/following{/other_user}","gists_url":"https://api.github.com/users/mvh77/gists{/gist_id}","starred_url":"https://api.github.com/users/mvh77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvh77/subscriptions","organizations_url":"https://api.github.com/users/mvh77/orgs","repos_url":"https://api.github.com/users/mvh77/repos","events_url":"https://api.github.com/users/mvh77/events{/privacy}","received_events_url":"https://api.github.com/users/mvh77/received_events","type":"User","site_admin":false},"body":"Ok this should be gold now! :stuck_out_tongue:","created_at":"2017-03-16T18:34:23Z","updated_at":"2017-03-17T17:41:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"87f3c11f6d7c7433d2aba96a716d489f5c1a716a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/scala-js/scala-js/pulls/2809/commits","review_comments_url":"https://api.github.com/repos/scala-js/scala-js/pulls/2809/comments","review_comment_url":"https://api.github.com/repos/scala-js/scala-js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scala-js/scala-js/issues/2809/comments","statuses_url":"https://api.github.com/repos/scala-js/scala-js/statuses/b4e0e1e6495553446e2341a405deb7be9e7374f0","head":{"label":"mvh77:base64","ref":"base64","sha":"b4e0e1e6495553446e2341a405deb7be9e7374f0","user":{"login":"mvh77","id":15170363,"avatar_url":"https://avatars1.githubusercontent.com/u/15170363?v=3","gravatar_id":"","url":"https://api.github.com/users/mvh77","html_url":"https://github.com/mvh77","followers_url":"https://api.github.com/users/mvh77/followers","following_url":"https://api.github.com/users/mvh77/following{/other_user}","gists_url":"https://api.github.com/users/mvh77/gists{/gist_id}","starred_url":"https://api.github.com/users/mvh77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvh77/subscriptions","organizations_url":"https://api.github.com/users/mvh77/orgs","repos_url":"https://api.github.com/users/mvh77/repos","events_url":"https://api.github.com/users/mvh77/events{/privacy}","received_events_url":"https://api.github.com/users/mvh77/received_events","type":"User","site_admin":false},"repo":{"id":83595101,"name":"scala-js","full_name":"mvh77/scala-js","owner":{"login":"mvh77","id":15170363,"avatar_url":"https://avatars1.githubusercontent.com/u/15170363?v=3","gravatar_id":"","url":"https://api.github.com/users/mvh77","html_url":"https://github.com/mvh77","followers_url":"https://api.github.com/users/mvh77/followers","following_url":"https://api.github.com/users/mvh77/following{/other_user}","gists_url":"https://api.github.com/users/mvh77/gists{/gist_id}","starred_url":"https://api.github.com/users/mvh77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvh77/subscriptions","organizations_url":"https://api.github.com/users/mvh77/orgs","repos_url":"https://api.github.com/users/mvh77/repos","events_url":"https://api.github.com/users/mvh77/events{/privacy}","received_events_url":"https://api.github.com/users/mvh77/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mvh77/scala-js","description":"Scala.js, the Scala to JavaScript compiler","fork":true,"url":"https://api.github.com/repos/mvh77/scala-js","forks_url":"https://api.github.com/repos/mvh77/scala-js/forks","keys_url":"https://api.github.com/repos/mvh77/scala-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mvh77/scala-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mvh77/scala-js/teams","hooks_url":"https://api.github.com/repos/mvh77/scala-js/hooks","issue_events_url":"https://api.github.com/repos/mvh77/scala-js/issues/events{/number}","events_url":"https://api.github.com/repos/mvh77/scala-js/events","assignees_url":"https://api.github.com/repos/mvh77/scala-js/assignees{/user}","branches_url":"https://api.github.com/repos/mvh77/scala-js/branches{/branch}","tags_url":"https://api.github.com/repos/mvh77/scala-js/tags","blobs_url":"https://api.github.com/repos/mvh77/scala-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mvh77/scala-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mvh77/scala-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/mvh77/scala-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mvh77/scala-js/statuses/{sha}","languages_url":"https://api.github.com/repos/mvh77/scala-js/languages","stargazers_url":"https://api.github.com/repos/mvh77/scala-js/stargazers","contributors_url":"https://api.github.com/repos/mvh77/scala-js/contributors","subscribers_url":"https://api.github.com/repos/mvh77/scala-js/subscribers","subscription_url":"https://api.github.com/repos/mvh77/scala-js/subscription","commits_url":"https://api.github.com/repos/mvh77/scala-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/mvh77/scala-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/mvh77/scala-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/mvh77/scala-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/mvh77/scala-js/contents/{+path}","compare_url":"https://api.github.com/repos/mvh77/scala-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mvh77/scala-js/merges","archive_url":"https://api.github.com/repos/mvh77/scala-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mvh77/scala-js/downloads","issues_url":"https://api.github.com/repos/mvh77/scala-js/issues{/number}","pulls_url":"https://api.github.com/repos/mvh77/scala-js/pulls{/number}","milestones_url":"https://api.github.com/repos/mvh77/scala-js/milestones{/number}","notifications_url":"https://api.github.com/repos/mvh77/scala-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mvh77/scala-js/labels{/name}","releases_url":"https://api.github.com/repos/mvh77/scala-js/releases{/id}","deployments_url":"https://api.github.com/repos/mvh77/scala-js/deployments","created_at":"2017-03-01T19:54:12Z","updated_at":"2017-03-01T19:54:17Z","pushed_at":"2017-03-16T18:26:36Z","git_url":"git://github.com/mvh77/scala-js.git","ssh_url":"git@github.com:mvh77/scala-js.git","clone_url":"https://github.com/mvh77/scala-js.git","svn_url":"https://github.com/mvh77/scala-js","homepage":"https://www.scala-js.org/","size":13702,"stargazers_count":0,"watchers_count":0,"language":"Scala","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":"master"}},"base":{"label":"scala-js:master","ref":"master","sha":"9d4fe20dc757ab0abbb6a0b8c06ed552781aebf8","user":{"login":"scala-js","id":6039724,"avatar_url":"https://avatars0.githubusercontent.com/u/6039724?v=3","gravatar_id":"","url":"https://api.github.com/users/scala-js","html_url":"https://github.com/scala-js","followers_url":"https://api.github.com/users/scala-js/followers","following_url":"https://api.github.com/users/scala-js/following{/other_user}","gists_url":"https://api.github.com/users/scala-js/gists{/gist_id}","starred_url":"https://api.github.com/users/scala-js/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala-js/subscriptions","organizations_url":"https://api.github.com/users/scala-js/orgs","repos_url":"https://api.github.com/users/scala-js/repos","events_url":"https://api.github.com/users/scala-js/events{/privacy}","received_events_url":"https://api.github.com/users/scala-js/received_events","type":"Organization","site_admin":false},"repo":{"id":8272315,"name":"scala-js","full_name":"scala-js/scala-js","owner":{"login":"scala-js","id":6039724,"avatar_url":"https://avatars0.githubusercontent.com/u/6039724?v=3","gravatar_id":"","url":"https://api.github.com/users/scala-js","html_url":"https://github.com/scala-js","followers_url":"https://api.github.com/users/scala-js/followers","following_url":"https://api.github.com/users/scala-js/following{/other_user}","gists_url":"https://api.github.com/users/scala-js/gists{/gist_id}","starred_url":"https://api.github.com/users/scala-js/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala-js/subscriptions","organizations_url":"https://api.github.com/users/scala-js/orgs","repos_url":"https://api.github.com/users/scala-js/repos","events_url":"https://api.github.com/users/scala-js/events{/privacy}","received_events_url":"https://api.github.com/users/scala-js/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scala-js/scala-js","description":"Scala.js, the Scala to JavaScript compiler","fork":false,"url":"https://api.github.com/repos/scala-js/scala-js","forks_url":"https://api.github.com/repos/scala-js/scala-js/forks","keys_url":"https://api.github.com/repos/scala-js/scala-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scala-js/scala-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scala-js/scala-js/teams","hooks_url":"https://api.github.com/repos/scala-js/scala-js/hooks","issue_events_url":"https://api.github.com/repos/scala-js/scala-js/issues/events{/number}","events_url":"https://api.github.com/repos/scala-js/scala-js/events","assignees_url":"https://api.github.com/repos/scala-js/scala-js/assignees{/user}","branches_url":"https://api.github.com/repos/scala-js/scala-js/branches{/branch}","tags_url":"https://api.github.com/repos/scala-js/scala-js/tags","blobs_url":"https://api.github.com/repos/scala-js/scala-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scala-js/scala-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scala-js/scala-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/scala-js/scala-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scala-js/scala-js/statuses/{sha}","languages_url":"https://api.github.com/repos/scala-js/scala-js/languages","stargazers_url":"https://api.github.com/repos/scala-js/scala-js/stargazers","contributors_url":"https://api.github.com/repos/scala-js/scala-js/contributors","subscribers_url":"https://api.github.com/repos/scala-js/scala-js/subscribers","subscription_url":"https://api.github.com/repos/scala-js/scala-js/subscription","commits_url":"https://api.github.com/repos/scala-js/scala-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/scala-js/scala-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/scala-js/scala-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/scala-js/scala-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/scala-js/scala-js/contents/{+path}","compare_url":"https://api.github.com/repos/scala-js/scala-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scala-js/scala-js/merges","archive_url":"https://api.github.com/repos/scala-js/scala-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scala-js/scala-js/downloads","issues_url":"https://api.github.com/repos/scala-js/scala-js/issues{/number}","pulls_url":"https://api.github.com/repos/scala-js/scala-js/pulls{/number}","milestones_url":"https://api.github.com/repos/scala-js/scala-js/milestones{/number}","notifications_url":"https://api.github.com/repos/scala-js/scala-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scala-js/scala-js/labels{/name}","releases_url":"https://api.github.com/repos/scala-js/scala-js/releases{/id}","deployments_url":"https://api.github.com/repos/scala-js/scala-js/deployments","created_at":"2013-02-18T16:33:55Z","updated_at":"2017-03-17T16:34:41Z","pushed_at":"2017-03-17T07:05:30Z","git_url":"git://github.com/scala-js/scala-js.git","ssh_url":"git@github.com:scala-js/scala-js.git","clone_url":"https://github.com/scala-js/scala-js.git","svn_url":"https://github.com/scala-js/scala-js","homepage":"https://www.scala-js.org/","size":13689,"stargazers_count":2859,"watchers_count":2859,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":251,"mirror_url":null,"open_issues_count":93,"forks":251,"open_issues":93,"watchers":2859,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/2809"},"html":{"href":"https://github.com/scala-js/scala-js/pull/2809"},"issue":{"href":"https://api.github.com/repos/scala-js/scala-js/issues/2809"},"comments":{"href":"https://api.github.com/repos/scala-js/scala-js/issues/2809/comments"},"review_comments":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/2809/comments"},"review_comment":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/2809/commits"},"statuses":{"href":"https://api.github.com/repos/scala-js/scala-js/statuses/b4e0e1e6495553446e2341a405deb7be9e7374f0"}}}}
{"actor":{"display_login":"mvh77"}}