{"action":"created","comment":{"url":"https://api.github.com/repos/scala-js/scala-js/pulls/comments/64479584","id":64479584,"diff_hunk":"@@ -72,6 +74,73 @@ private[scalajs] final class ScalaJSClassEmitter(\n \n   private[emitter] def semantics: Semantics = linkingUnit.semantics\n \n+  private[emitter] lazy val typeTags: Map[LinkedClass, Int] = {\n+    import Definitions.ReservedTags\n+\n+    val childrenMap =\n+      linkingUnit.classDefs.groupBy(_.superClass.map(_.name)).withDefaultValue(Nil)\n+\n+    // Some classes may have parents that have been removed\n+    val orphans = for(cls <- linkingUnit.classDefs;\n+                    parent <- cls.superClass\n+                    if !linkedClassByName.isDefinedAt(parent.name)) yield cls\n+\n+    val roots = childrenMap(None) ++ orphans\n+\n+    @tailrec def getTypeTags(curTag: Int, stack: Seq[LinkedClass],\n+      accu: Map[LinkedClass, Int] = Map.empty): Map[LinkedClass, Int] = stack match {\n+      case cur +: rest if ReservedTags.isDefinedAt(cur.name.name) =>\n+        val children = childrenMap(Some(cur.name.name))\n+        val tag = ReservedTags(cur.name.name)\n+        getTypeTags(curTag, children ++ rest, accu + (cur -> tag))\n+\n+      case cur +: rest =>\n+        val nextTag = curTag + 1\n+        val children = childrenMap(Some(cur.name.name))\n+        getTypeTags(nextTag, children ++ rest, accu + (cur -> curTag))\n+\n+      case Nil =>\n+        // Sanity check: all classDefs must have a tag\n+        assert(linkingUnit.classDefs.forall(accu.isDefinedAt))\n+        accu\n+    }","path":"tools/shared/src/main/scala/org/scalajs/core/tools/linker/backend/emitter/ScalaJSClassEmitter.scala","position":42,"original_position":42,"commit_id":"e1473c09cb34833b2c0d322837acb4e7fa89cfcb","original_commit_id":"e1473c09cb34833b2c0d322837acb4e7fa89cfcb","user":{"login":"sjrd","id":535934,"avatar_url":"https://avatars.githubusercontent.com/u/535934?v=3","gravatar_id":"","url":"https://api.github.com/users/sjrd","html_url":"https://github.com/sjrd","followers_url":"https://api.github.com/users/sjrd/followers","following_url":"https://api.github.com/users/sjrd/following{/other_user}","gists_url":"https://api.github.com/users/sjrd/gists{/gist_id}","starred_url":"https://api.github.com/users/sjrd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sjrd/subscriptions","organizations_url":"https://api.github.com/users/sjrd/orgs","repos_url":"https://api.github.com/users/sjrd/repos","events_url":"https://api.github.com/users/sjrd/events{/privacy}","received_events_url":"https://api.github.com/users/sjrd/received_events","type":"User","site_admin":false},"body":"The reified `stack` is a useless complication. You should simply write a (non-tail-)recursive function that walks the tree. The tree's depth is never going so big that we can avoid a StackOverflowError by using an on-heap stack.\r\n\r\nThis also avoids all the manipulations of these `Seq`s, which are not super efficient.\r\n\r\nFinally, I suggest using a `Map.newBuilder[LinkedClass, Int]` and mutable additions to it, instead of trying to stay functional for the sake of it.","created_at":"2016-05-24T21:40:23Z","updated_at":"2016-05-24T21:40:23Z","html_url":"https://github.com/scala-js/scala-js/pull/2411#discussion_r64479584","pull_request_url":"https://api.github.com/repos/scala-js/scala-js/pulls/2411","_links":{"self":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/comments/64479584"},"html":{"href":"https://github.com/scala-js/scala-js/pull/2411#discussion_r64479584"},"pull_request":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/2411"}}},"pull_request":{"url":"https://api.github.com/repos/scala-js/scala-js/pulls/2411","id":71125244,"html_url":"https://github.com/scala-js/scala-js/pull/2411","diff_url":"https://github.com/scala-js/scala-js/pull/2411.diff","patch_url":"https://github.com/scala-js/scala-js/pull/2411.patch","issue_url":"https://api.github.com/repos/scala-js/scala-js/issues/2411","number":2411,"state":"open","locked":false,"title":"DO NOT MERGE: Fix #2066 : Improve performance of isInstanceOf","user":{"login":"paullepoulpe","id":1906266,"avatar_url":"https://avatars.githubusercontent.com/u/1906266?v=3","gravatar_id":"","url":"https://api.github.com/users/paullepoulpe","html_url":"https://github.com/paullepoulpe","followers_url":"https://api.github.com/users/paullepoulpe/followers","following_url":"https://api.github.com/users/paullepoulpe/following{/other_user}","gists_url":"https://api.github.com/users/paullepoulpe/gists{/gist_id}","starred_url":"https://api.github.com/users/paullepoulpe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paullepoulpe/subscriptions","organizations_url":"https://api.github.com/users/paullepoulpe/orgs","repos_url":"https://api.github.com/users/paullepoulpe/repos","events_url":"https://api.github.com/users/paullepoulpe/events{/privacy}","received_events_url":"https://api.github.com/users/paullepoulpe/received_events","type":"User","site_admin":false},"body":"Waiting for @tOverney's changes to the IncEmitter to fix incrementality (see discussion on #2142 ).","created_at":"2016-05-23T21:40:47Z","updated_at":"2016-05-24T21:40:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e3143be78d28bccf9c1befc800625b701325a9d1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scala-js/scala-js/pulls/2411/commits","review_comments_url":"https://api.github.com/repos/scala-js/scala-js/pulls/2411/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/2411/comments","statuses_url":"https://api.github.com/repos/scala-js/scala-js/statuses/e1473c09cb34833b2c0d322837acb4e7fa89cfcb","head":{"label":"paullepoulpe:opt-instanceof","ref":"opt-instanceof","sha":"e1473c09cb34833b2c0d322837acb4e7fa89cfcb","user":{"login":"paullepoulpe","id":1906266,"avatar_url":"https://avatars.githubusercontent.com/u/1906266?v=3","gravatar_id":"","url":"https://api.github.com/users/paullepoulpe","html_url":"https://github.com/paullepoulpe","followers_url":"https://api.github.com/users/paullepoulpe/followers","following_url":"https://api.github.com/users/paullepoulpe/following{/other_user}","gists_url":"https://api.github.com/users/paullepoulpe/gists{/gist_id}","starred_url":"https://api.github.com/users/paullepoulpe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paullepoulpe/subscriptions","organizations_url":"https://api.github.com/users/paullepoulpe/orgs","repos_url":"https://api.github.com/users/paullepoulpe/repos","events_url":"https://api.github.com/users/paullepoulpe/events{/privacy}","received_events_url":"https://api.github.com/users/paullepoulpe/received_events","type":"User","site_admin":false},"repo":{"id":59460352,"name":"scala-js","full_name":"paullepoulpe/scala-js","owner":{"login":"paullepoulpe","id":1906266,"avatar_url":"https://avatars.githubusercontent.com/u/1906266?v=3","gravatar_id":"","url":"https://api.github.com/users/paullepoulpe","html_url":"https://github.com/paullepoulpe","followers_url":"https://api.github.com/users/paullepoulpe/followers","following_url":"https://api.github.com/users/paullepoulpe/following{/other_user}","gists_url":"https://api.github.com/users/paullepoulpe/gists{/gist_id}","starred_url":"https://api.github.com/users/paullepoulpe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paullepoulpe/subscriptions","organizations_url":"https://api.github.com/users/paullepoulpe/orgs","repos_url":"https://api.github.com/users/paullepoulpe/repos","events_url":"https://api.github.com/users/paullepoulpe/events{/privacy}","received_events_url":"https://api.github.com/users/paullepoulpe/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/paullepoulpe/scala-js","description":"Scala.js, the Scala to JavaScript compiler","fork":true,"url":"https://api.github.com/repos/paullepoulpe/scala-js","forks_url":"https://api.github.com/repos/paullepoulpe/scala-js/forks","keys_url":"https://api.github.com/repos/paullepoulpe/scala-js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paullepoulpe/scala-js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paullepoulpe/scala-js/teams","hooks_url":"https://api.github.com/repos/paullepoulpe/scala-js/hooks","issue_events_url":"https://api.github.com/repos/paullepoulpe/scala-js/issues/events{/number}","events_url":"https://api.github.com/repos/paullepoulpe/scala-js/events","assignees_url":"https://api.github.com/repos/paullepoulpe/scala-js/assignees{/user}","branches_url":"https://api.github.com/repos/paullepoulpe/scala-js/branches{/branch}","tags_url":"https://api.github.com/repos/paullepoulpe/scala-js/tags","blobs_url":"https://api.github.com/repos/paullepoulpe/scala-js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paullepoulpe/scala-js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paullepoulpe/scala-js/git/refs{/sha}","trees_url":"https://api.github.com/repos/paullepoulpe/scala-js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paullepoulpe/scala-js/statuses/{sha}","languages_url":"https://api.github.com/repos/paullepoulpe/scala-js/languages","stargazers_url":"https://api.github.com/repos/paullepoulpe/scala-js/stargazers","contributors_url":"https://api.github.com/repos/paullepoulpe/scala-js/contributors","subscribers_url":"https://api.github.com/repos/paullepoulpe/scala-js/subscribers","subscription_url":"https://api.github.com/repos/paullepoulpe/scala-js/subscription","commits_url":"https://api.github.com/repos/paullepoulpe/scala-js/commits{/sha}","git_commits_url":"https://api.github.com/repos/paullepoulpe/scala-js/git/commits{/sha}","comments_url":"https://api.github.com/repos/paullepoulpe/scala-js/comments{/number}","issue_comment_url":"https://api.github.com/repos/paullepoulpe/scala-js/issues/comments{/number}","contents_url":"https://api.github.com/repos/paullepoulpe/scala-js/contents/{+path}","compare_url":"https://api.github.com/repos/paullepoulpe/scala-js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paullepoulpe/scala-js/merges","archive_url":"https://api.github.com/repos/paullepoulpe/scala-js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paullepoulpe/scala-js/downloads","issues_url":"https://api.github.com/repos/paullepoulpe/scala-js/issues{/number}","pulls_url":"https://api.github.com/repos/paullepoulpe/scala-js/pulls{/number}","milestones_url":"https://api.github.com/repos/paullepoulpe/scala-js/milestones{/number}","notifications_url":"https://api.github.com/repos/paullepoulpe/scala-js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paullepoulpe/scala-js/labels{/name}","releases_url":"https://api.github.com/repos/paullepoulpe/scala-js/releases{/id}","deployments_url":"https://api.github.com/repos/paullepoulpe/scala-js/deployments","created_at":"2016-05-23T07:13:03Z","updated_at":"2016-05-23T07:13:07Z","pushed_at":"2016-05-23T21:35:36Z","git_url":"git://github.com/paullepoulpe/scala-js.git","ssh_url":"git@github.com:paullepoulpe/scala-js.git","clone_url":"https://github.com/paullepoulpe/scala-js.git","svn_url":"https://github.com/paullepoulpe/scala-js","homepage":"https://www.scala-js.org/","size":11857,"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":"cf04cc375e0a138b452cea6c3d39c6cf1e000478","user":{"login":"scala-js","id":6039724,"avatar_url":"https://avatars.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://avatars.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":"2016-05-24T15:16:38Z","pushed_at":"2016-05-24T18:17:34Z","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":14917,"stargazers_count":2330,"watchers_count":2330,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":213,"mirror_url":null,"open_issues_count":98,"forks":213,"open_issues":98,"watchers":2330,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/2411"},"html":{"href":"https://github.com/scala-js/scala-js/pull/2411"},"issue":{"href":"https://api.github.com/repos/scala-js/scala-js/issues/2411"},"comments":{"href":"https://api.github.com/repos/scala-js/scala-js/issues/2411/comments"},"review_comments":{"href":"https://api.github.com/repos/scala-js/scala-js/pulls/2411/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/2411/commits"},"statuses":{"href":"https://api.github.com/repos/scala-js/scala-js/statuses/e1473c09cb34833b2c0d322837acb4e7fa89cfcb"}}}}
{"actor":{"display_login":"sjrd"}}