{"action":"created","comment":{"url":"https://api.github.com/repos/google/agera/pulls/comments/74694743","id":74694743,"diff_hunk":"@@ -197,52 +191,81 @@ public Function thenSort(@NonNull final Comparator comparator) {\n     @SuppressWarnings(\"unchecked\")\n     public Object apply(@NonNull final Object input) {\n       Object item = input;\n-      for (final Function function : functions) {\n-        item = function.apply(item);\n-      }\n-      return item;\n-    }\n-  }\n-\n-  private static final class FilterFunction<T> implements Function<List<T>, List<T>> {\n-    @NonNull\n-    private final Predicate filter;\n-\n-    FilterFunction(@NonNull final Predicate filter) {\n-      this.filter = checkNotNull(filter);\n-    }\n+      boolean compilerList = false;\n+      int i = 0;\n+      final int length = functions.length;\n+      while (i < length) {\n+        final int type = (int) functions[i++];\n+        final Object command = functions[i++];\n+        switch (type) {\n+          case LIMIT: {\n+            final List list = (List) item;\n+            final int limit = (int) command;\n+            if (limit <= 0) {\n+              item = emptyList();\n+            } else if (list.size() < limit) {\n+              item = input;\n+            } else {\n+              final List subList = list.subList(0, limit);\n+              item = compilerList ? subList : new ArrayList<>(subList);\n+              compilerList = true;\n+            }\n+          }\n+          break;\n+          case FILTER: {\n+            final List list = (List) item;\n+            if (list.isEmpty()) {\n+              item = emptyList();\n+            } else {\n+              final int size = list.size();\n+              final List result = new ArrayList(size);\n+              for (int j = 0; j < size; j++) {\n+                final Object listItem = list.get(j);\n+                if (((Predicate) command).apply(listItem)) {\n+                  result.add(listItem);\n+                }\n+              }\n+              item = result;\n+              compilerList = true;\n+            }\n+          }\n+          break;\n+          case SORT: {\n+            final List output = compilerList ? ((List) item) : new ArrayList<>(((List) item));\n+            Collections.sort(output, (Comparator) command);\n+            item = output;\n+            compilerList = true;\n+          }\n+          break;\n+          case MAP: {\n+            final List list = (List) item;\n+            final int size = list.size();\n+            if (list.isEmpty()) {\n+              item = emptyList();\n+            } else if (compilerList) {\n+              for (int j = 0; j < size; j++) {\n+                list.set(j, ((Function) command).apply(list.get(j)));","path":"agera/src/main/java/com/google/android/agera/FunctionCompiler.java","position":227,"original_position":227,"commit_id":"3020b4ee11c989412237f59e9bf3186ea515cc33","original_commit_id":"3020b4ee11c989412237f59e9bf3186ea515cc33","user":{"login":"maxtroy","id":16337072,"avatar_url":"https://avatars.githubusercontent.com/u/16337072?v=3","gravatar_id":"","url":"https://api.github.com/users/maxtroy","html_url":"https://github.com/maxtroy","followers_url":"https://api.github.com/users/maxtroy/followers","following_url":"https://api.github.com/users/maxtroy/following{/other_user}","gists_url":"https://api.github.com/users/maxtroy/gists{/gist_id}","starred_url":"https://api.github.com/users/maxtroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxtroy/subscriptions","organizations_url":"https://api.github.com/users/maxtroy/orgs","repos_url":"https://api.github.com/users/maxtroy/repos","events_url":"https://api.github.com/users/maxtroy/events{/privacy}","received_events_url":"https://api.github.com/users/maxtroy/received_events","type":"User","site_admin":false},"body":"this cast probably incurs runtime type-checking overhead, so do it outside the for-loop.","created_at":"2016-08-14T01:57:45Z","updated_at":"2016-08-14T01:57:45Z","html_url":"https://github.com/google/agera/pull/95#discussion_r74694743","pull_request_url":"https://api.github.com/repos/google/agera/pulls/95","_links":{"self":{"href":"https://api.github.com/repos/google/agera/pulls/comments/74694743"},"html":{"href":"https://github.com/google/agera/pull/95#discussion_r74694743"},"pull_request":{"href":"https://api.github.com/repos/google/agera/pulls/95"}}},"pull_request":{"url":"https://api.github.com/repos/google/agera/pulls/95","id":81202529,"html_url":"https://github.com/google/agera/pull/95","diff_url":"https://github.com/google/agera/pull/95.diff","patch_url":"https://github.com/google/agera/pull/95.patch","issue_url":"https://api.github.com/repos/google/agera/issues/95","number":95,"state":"open","locked":false,"title":"Made function compiler more memory efficient","user":{"login":"ernstsson","id":378389,"avatar_url":"https://avatars.githubusercontent.com/u/378389?v=3","gravatar_id":"","url":"https://api.github.com/users/ernstsson","html_url":"https://github.com/ernstsson","followers_url":"https://api.github.com/users/ernstsson/followers","following_url":"https://api.github.com/users/ernstsson/following{/other_user}","gists_url":"https://api.github.com/users/ernstsson/gists{/gist_id}","starred_url":"https://api.github.com/users/ernstsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ernstsson/subscriptions","organizations_url":"https://api.github.com/users/ernstsson/orgs","repos_url":"https://api.github.com/users/ernstsson/repos","events_url":"https://api.github.com/users/ernstsson/events{/privacy}","received_events_url":"https://api.github.com/users/ernstsson/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-08-13T01:08:18Z","updated_at":"2016-08-14T01:57:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4aa2a7908b4332eac0d82ea138510b2c3ea1fbd3","assignee":{"login":"maxtroy","id":16337072,"avatar_url":"https://avatars.githubusercontent.com/u/16337072?v=3","gravatar_id":"","url":"https://api.github.com/users/maxtroy","html_url":"https://github.com/maxtroy","followers_url":"https://api.github.com/users/maxtroy/followers","following_url":"https://api.github.com/users/maxtroy/following{/other_user}","gists_url":"https://api.github.com/users/maxtroy/gists{/gist_id}","starred_url":"https://api.github.com/users/maxtroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxtroy/subscriptions","organizations_url":"https://api.github.com/users/maxtroy/orgs","repos_url":"https://api.github.com/users/maxtroy/repos","events_url":"https://api.github.com/users/maxtroy/events{/privacy}","received_events_url":"https://api.github.com/users/maxtroy/received_events","type":"User","site_admin":false},"assignees":[{"login":"maxtroy","id":16337072,"avatar_url":"https://avatars.githubusercontent.com/u/16337072?v=3","gravatar_id":"","url":"https://api.github.com/users/maxtroy","html_url":"https://github.com/maxtroy","followers_url":"https://api.github.com/users/maxtroy/followers","following_url":"https://api.github.com/users/maxtroy/following{/other_user}","gists_url":"https://api.github.com/users/maxtroy/gists{/gist_id}","starred_url":"https://api.github.com/users/maxtroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxtroy/subscriptions","organizations_url":"https://api.github.com/users/maxtroy/orgs","repos_url":"https://api.github.com/users/maxtroy/repos","events_url":"https://api.github.com/users/maxtroy/events{/privacy}","received_events_url":"https://api.github.com/users/maxtroy/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/google/agera/milestones/2","html_url":"https://github.com/google/agera/milestones/v1.2","labels_url":"https://api.github.com/repos/google/agera/milestones/2/labels","id":1828528,"number":2,"title":"v1.2","description":null,"creator":{"login":"ernstsson","id":378389,"avatar_url":"https://avatars.githubusercontent.com/u/378389?v=3","gravatar_id":"","url":"https://api.github.com/users/ernstsson","html_url":"https://github.com/ernstsson","followers_url":"https://api.github.com/users/ernstsson/followers","following_url":"https://api.github.com/users/ernstsson/following{/other_user}","gists_url":"https://api.github.com/users/ernstsson/gists{/gist_id}","starred_url":"https://api.github.com/users/ernstsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ernstsson/subscriptions","organizations_url":"https://api.github.com/users/ernstsson/orgs","repos_url":"https://api.github.com/users/ernstsson/repos","events_url":"https://api.github.com/users/ernstsson/events{/privacy}","received_events_url":"https://api.github.com/users/ernstsson/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":5,"state":"open","created_at":"2016-06-15T09:13:21Z","updated_at":"2016-08-13T01:08:19Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/google/agera/pulls/95/commits","review_comments_url":"https://api.github.com/repos/google/agera/pulls/95/comments","review_comment_url":"https://api.github.com/repos/google/agera/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/agera/issues/95/comments","statuses_url":"https://api.github.com/repos/google/agera/statuses/3020b4ee11c989412237f59e9bf3186ea515cc33","head":{"label":"ernstsson:funcreuse","ref":"funcreuse","sha":"3020b4ee11c989412237f59e9bf3186ea515cc33","user":{"login":"ernstsson","id":378389,"avatar_url":"https://avatars.githubusercontent.com/u/378389?v=3","gravatar_id":"","url":"https://api.github.com/users/ernstsson","html_url":"https://github.com/ernstsson","followers_url":"https://api.github.com/users/ernstsson/followers","following_url":"https://api.github.com/users/ernstsson/following{/other_user}","gists_url":"https://api.github.com/users/ernstsson/gists{/gist_id}","starred_url":"https://api.github.com/users/ernstsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ernstsson/subscriptions","organizations_url":"https://api.github.com/users/ernstsson/orgs","repos_url":"https://api.github.com/users/ernstsson/repos","events_url":"https://api.github.com/users/ernstsson/events{/privacy}","received_events_url":"https://api.github.com/users/ernstsson/received_events","type":"User","site_admin":false},"repo":{"id":56751789,"name":"agera","full_name":"ernstsson/agera","owner":{"login":"ernstsson","id":378389,"avatar_url":"https://avatars.githubusercontent.com/u/378389?v=3","gravatar_id":"","url":"https://api.github.com/users/ernstsson","html_url":"https://github.com/ernstsson","followers_url":"https://api.github.com/users/ernstsson/followers","following_url":"https://api.github.com/users/ernstsson/following{/other_user}","gists_url":"https://api.github.com/users/ernstsson/gists{/gist_id}","starred_url":"https://api.github.com/users/ernstsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ernstsson/subscriptions","organizations_url":"https://api.github.com/users/ernstsson/orgs","repos_url":"https://api.github.com/users/ernstsson/repos","events_url":"https://api.github.com/users/ernstsson/events{/privacy}","received_events_url":"https://api.github.com/users/ernstsson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ernstsson/agera","description":"Reactive Programming for Android","fork":true,"url":"https://api.github.com/repos/ernstsson/agera","forks_url":"https://api.github.com/repos/ernstsson/agera/forks","keys_url":"https://api.github.com/repos/ernstsson/agera/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ernstsson/agera/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ernstsson/agera/teams","hooks_url":"https://api.github.com/repos/ernstsson/agera/hooks","issue_events_url":"https://api.github.com/repos/ernstsson/agera/issues/events{/number}","events_url":"https://api.github.com/repos/ernstsson/agera/events","assignees_url":"https://api.github.com/repos/ernstsson/agera/assignees{/user}","branches_url":"https://api.github.com/repos/ernstsson/agera/branches{/branch}","tags_url":"https://api.github.com/repos/ernstsson/agera/tags","blobs_url":"https://api.github.com/repos/ernstsson/agera/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ernstsson/agera/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ernstsson/agera/git/refs{/sha}","trees_url":"https://api.github.com/repos/ernstsson/agera/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ernstsson/agera/statuses/{sha}","languages_url":"https://api.github.com/repos/ernstsson/agera/languages","stargazers_url":"https://api.github.com/repos/ernstsson/agera/stargazers","contributors_url":"https://api.github.com/repos/ernstsson/agera/contributors","subscribers_url":"https://api.github.com/repos/ernstsson/agera/subscribers","subscription_url":"https://api.github.com/repos/ernstsson/agera/subscription","commits_url":"https://api.github.com/repos/ernstsson/agera/commits{/sha}","git_commits_url":"https://api.github.com/repos/ernstsson/agera/git/commits{/sha}","comments_url":"https://api.github.com/repos/ernstsson/agera/comments{/number}","issue_comment_url":"https://api.github.com/repos/ernstsson/agera/issues/comments{/number}","contents_url":"https://api.github.com/repos/ernstsson/agera/contents/{+path}","compare_url":"https://api.github.com/repos/ernstsson/agera/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ernstsson/agera/merges","archive_url":"https://api.github.com/repos/ernstsson/agera/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ernstsson/agera/downloads","issues_url":"https://api.github.com/repos/ernstsson/agera/issues{/number}","pulls_url":"https://api.github.com/repos/ernstsson/agera/pulls{/number}","milestones_url":"https://api.github.com/repos/ernstsson/agera/milestones{/number}","notifications_url":"https://api.github.com/repos/ernstsson/agera/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ernstsson/agera/labels{/name}","releases_url":"https://api.github.com/repos/ernstsson/agera/releases{/id}","deployments_url":"https://api.github.com/repos/ernstsson/agera/deployments","created_at":"2016-04-21T07:25:16Z","updated_at":"2016-05-13T06:59:33Z","pushed_at":"2016-08-13T01:09:08Z","git_url":"git://github.com/ernstsson/agera.git","ssh_url":"git@github.com:ernstsson/agera.git","clone_url":"https://github.com/ernstsson/agera.git","svn_url":"https://github.com/ernstsson/agera","homepage":"","size":810,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":false,"has_wiki":false,"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":"google:master","ref":"master","sha":"ac38f82a004d2a6025108b20f4eb30fe231849fa","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":48175620,"name":"agera","full_name":"google/agera","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/agera","description":"Reactive Programming for Android","fork":false,"url":"https://api.github.com/repos/google/agera","forks_url":"https://api.github.com/repos/google/agera/forks","keys_url":"https://api.github.com/repos/google/agera/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/agera/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/agera/teams","hooks_url":"https://api.github.com/repos/google/agera/hooks","issue_events_url":"https://api.github.com/repos/google/agera/issues/events{/number}","events_url":"https://api.github.com/repos/google/agera/events","assignees_url":"https://api.github.com/repos/google/agera/assignees{/user}","branches_url":"https://api.github.com/repos/google/agera/branches{/branch}","tags_url":"https://api.github.com/repos/google/agera/tags","blobs_url":"https://api.github.com/repos/google/agera/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/agera/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/agera/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/agera/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/agera/statuses/{sha}","languages_url":"https://api.github.com/repos/google/agera/languages","stargazers_url":"https://api.github.com/repos/google/agera/stargazers","contributors_url":"https://api.github.com/repos/google/agera/contributors","subscribers_url":"https://api.github.com/repos/google/agera/subscribers","subscription_url":"https://api.github.com/repos/google/agera/subscription","commits_url":"https://api.github.com/repos/google/agera/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/agera/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/agera/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/agera/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/agera/contents/{+path}","compare_url":"https://api.github.com/repos/google/agera/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/agera/merges","archive_url":"https://api.github.com/repos/google/agera/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/agera/downloads","issues_url":"https://api.github.com/repos/google/agera/issues{/number}","pulls_url":"https://api.github.com/repos/google/agera/pulls{/number}","milestones_url":"https://api.github.com/repos/google/agera/milestones{/number}","notifications_url":"https://api.github.com/repos/google/agera/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/agera/labels{/name}","releases_url":"https://api.github.com/repos/google/agera/releases{/id}","deployments_url":"https://api.github.com/repos/google/agera/deployments","created_at":"2015-12-17T13:22:58Z","updated_at":"2016-08-13T15:55:29Z","pushed_at":"2016-08-14T01:43:12Z","git_url":"git://github.com/google/agera.git","ssh_url":"git@github.com:google/agera.git","clone_url":"https://github.com/google/agera.git","svn_url":"https://github.com/google/agera","homepage":"","size":1035,"stargazers_count":5600,"watchers_count":5600,"language":"Java","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":476,"mirror_url":null,"open_issues_count":5,"forks":476,"open_issues":5,"watchers":5600,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/agera/pulls/95"},"html":{"href":"https://github.com/google/agera/pull/95"},"issue":{"href":"https://api.github.com/repos/google/agera/issues/95"},"comments":{"href":"https://api.github.com/repos/google/agera/issues/95/comments"},"review_comments":{"href":"https://api.github.com/repos/google/agera/pulls/95/comments"},"review_comment":{"href":"https://api.github.com/repos/google/agera/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/agera/pulls/95/commits"},"statuses":{"href":"https://api.github.com/repos/google/agera/statuses/3020b4ee11c989412237f59e9bf3186ea515cc33"}}}}
{"actor":{"display_login":"maxtroy"}}