{"action":"created","comment":{"url":"https://api.github.com/repos/apache/thrift/pulls/comments/52825710","id":52825710,"diff_hunk":"@@ -1886,24 +1889,57 @@ void t_java_generator::generate_java_struct_equality(ofstream& out, t_struct* ts\n     bool can_be_null = type_can_be_null(t);\n     string name = (*m_iter)->get_name();\n \n-    string present = \"true\";\n+    if (is_optional || can_be_null) {\n+      indent(out) << \"hashCode = hashCode * \" << MUL << \" + ((\" << generate_isset_check(*m_iter)\n+                  << \") ? \" << B_YES << \" : \" << B_NO << \");\" << endl;\n+    }\n \n     if (is_optional || can_be_null) {\n-      present += \" && (\" + generate_isset_check(*m_iter) + \")\";\n+      indent(out) << \"if (\" + generate_isset_check(*m_iter) + \")\" << endl;\n+      indent_up();\n     }\n \n-    indent(out) << \"boolean present_\" << name << \" = \" << present << \";\" << endl;\n-    indent(out) << \"list.add(present_\" << name << \");\" << endl;\n-    indent(out) << \"if (present_\" << name << \")\" << endl;\n     if (t->is_enum()) {\n-      indent(out) << \"  list.add(\" << name << \".getValue());\" << endl;\n+      indent(out) << \"hashCode = hashCode * \" << MUL << \" + \" << name << \".getValue();\" << endl;\n+    } else if (t->is_base_type()) {\n+      switch(((t_base_type*)t)->get_base()) {\n+        case t_base_type::TYPE_VOID:\n+          break;\n+        case t_base_type::TYPE_STRING:\n+          indent(out) << \"hashCode = hashCode * \" << MUL << \" + \" << name << \".hashCode();\" << endl;\n+          break;\n+        case t_base_type::TYPE_BOOL:\n+          indent(out) << \"hashCode = hashCode * \" << MUL << \" + ((\" << name << \") ? \"\n+                      << B_YES << \" : \" << B_NO << \");\" << endl;\n+          break;\n+        case t_base_type::TYPE_I8:\n+          indent(out) << \"hashCode = hashCode * \" << MUL << \" + (int) (\" << name << \");\" << endl;\n+          break;\n+        case t_base_type::TYPE_I16:\n+        case t_base_type::TYPE_I32:\n+          indent(out) << \"hashCode = hashCode * \" << MUL << \" + \" << name << \";\" << endl;\n+          break;\n+        case t_base_type::TYPE_I64:\n+          indent(out) << \"hashCode = hashCode * \" << MUL << \" + org.apache.thrift.TBaseHelper.hashCode(\" << name << \");\" << endl;\n+          break;\n+        case t_base_type::TYPE_DOUBLE:\n+          indent(out) << \"hashCode = hashCode * \" << MUL << \" + org.apache.thrift.TBaseHelper.hashCode(\" << name << \");\" << endl;\n+          break;\n+        default:\n+          throw \"compiler error: the following base type has no hashcode generator: \" +\n+                 t_base_type::t_base_name(((t_base_type*)t)->get_base());","path":"compiler/cpp/src/generate/t_java_generator.cc","position":62,"original_position":62,"commit_id":"c79377cbbd0f0f14549714d8a71433d7f166eefe","original_commit_id":"c79377cbbd0f0f14549714d8a71433d7f166eefe","user":{"login":"nsuke","id":3064114,"avatar_url":"https://avatars.githubusercontent.com/u/3064114?v=3","gravatar_id":"","url":"https://api.github.com/users/nsuke","html_url":"https://github.com/nsuke","followers_url":"https://api.github.com/users/nsuke/followers","following_url":"https://api.github.com/users/nsuke/following{/other_user}","gists_url":"https://api.github.com/users/nsuke/gists{/gist_id}","starred_url":"https://api.github.com/users/nsuke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nsuke/subscriptions","organizations_url":"https://api.github.com/users/nsuke/orgs","repos_url":"https://api.github.com/users/nsuke/repos","events_url":"https://api.github.com/users/nsuke/events{/privacy}","received_events_url":"https://api.github.com/users/nsuke/received_events","type":"User","site_admin":false},"body":"Just a style nit, could you indent switch in the same way as the other part of this file (less indentation) ?","created_at":"2016-02-13T09:30:02Z","updated_at":"2016-02-13T09:30:02Z","html_url":"https://github.com/apache/thrift/pull/448#discussion_r52825710","pull_request_url":"https://api.github.com/repos/apache/thrift/pulls/448","_links":{"self":{"href":"https://api.github.com/repos/apache/thrift/pulls/comments/52825710"},"html":{"href":"https://github.com/apache/thrift/pull/448#discussion_r52825710"},"pull_request":{"href":"https://api.github.com/repos/apache/thrift/pulls/448"}}},"pull_request":{"url":"https://api.github.com/repos/apache/thrift/pulls/448","id":33527477,"html_url":"https://github.com/apache/thrift/pull/448","diff_url":"https://github.com/apache/thrift/pull/448.diff","patch_url":"https://github.com/apache/thrift/pull/448.patch","issue_url":"https://api.github.com/repos/apache/thrift/issues/448","number":448,"state":"open","locked":false,"title":"THRIFT-2877 Generate hashCode using primitives, static utility methods","user":{"login":"roshan","id":7322596,"avatar_url":"https://avatars.githubusercontent.com/u/7322596?v=3","gravatar_id":"","url":"https://api.github.com/users/roshan","html_url":"https://github.com/roshan","followers_url":"https://api.github.com/users/roshan/followers","following_url":"https://api.github.com/users/roshan/following{/other_user}","gists_url":"https://api.github.com/users/roshan/gists{/gist_id}","starred_url":"https://api.github.com/users/roshan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roshan/subscriptions","organizations_url":"https://api.github.com/users/roshan/orgs","repos_url":"https://api.github.com/users/roshan/repos","events_url":"https://api.github.com/users/roshan/events{/privacy}","received_events_url":"https://api.github.com/users/roshan/received_events","type":"User","site_admin":false},"body":"This is pretty much the List.hashCode() except without any list. It takes about a third the time on some rudimentary benchmarks. I tried it out with\r\n\r\n```\r\ntypedef i32 SomeId\r\ntypedef binary BinId\r\ntypedef string StringId\r\n\r\nstruct NonTrue {}\r\n\r\nunion MaybeAThing {\r\n    1: NonTrue nt\r\n    2: bool bl\r\n}\r\n\r\nenum Nomnom {\r\n    EAT=31\r\n    LIVE=515\r\n}\r\n\r\nstruct AllPrims {\r\n    1: bool boole\r\n    2: byte single_byte\r\n    3: i16 shrt\r\n    4: i32 integ\r\n    5: i64 longue\r\n    6: double f64\r\n    7: string str\r\n    8: binary bin\r\n    9: Nomnom en\r\n    10: NonTrue stru\r\n    11: MaybeAThing un\r\n    12: SomeId intid\r\n    13: BinId binid\r\n    14: StringId strid\r\n}\r\n```\r\n\r\ngenerating [this hashCode()](https://gist.github.com/roshan/7b7fff349e3ed06322c3).\r\n\r\nPopulating these structs with some values has it match the AbstractList.hashCode() result but maybe we could try a different multiplicative factor.\r\n\r\nSorry about the other one https://github.com/apache/thrift/pull/447. I rebased to one commit, but couldn't seem to reuse the old PR (it compiled locally on gcc but failed on clang).","created_at":"2015-04-17T09:24:29Z","updated_at":"2016-02-13T09:30:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0c4f9322c872ba1f11bd53a6ef6a1cd5efd2824b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/thrift/pulls/448/commits","review_comments_url":"https://api.github.com/repos/apache/thrift/pulls/448/comments","review_comment_url":"https://api.github.com/repos/apache/thrift/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/thrift/issues/448/comments","statuses_url":"https://api.github.com/repos/apache/thrift/statuses/c79377cbbd0f0f14549714d8a71433d7f166eefe","head":{"label":"roshan:THRIFT-2877_int_based_hashcode","ref":"THRIFT-2877_int_based_hashcode","sha":"c79377cbbd0f0f14549714d8a71433d7f166eefe","user":{"login":"roshan","id":7322596,"avatar_url":"https://avatars.githubusercontent.com/u/7322596?v=3","gravatar_id":"","url":"https://api.github.com/users/roshan","html_url":"https://github.com/roshan","followers_url":"https://api.github.com/users/roshan/followers","following_url":"https://api.github.com/users/roshan/following{/other_user}","gists_url":"https://api.github.com/users/roshan/gists{/gist_id}","starred_url":"https://api.github.com/users/roshan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roshan/subscriptions","organizations_url":"https://api.github.com/users/roshan/orgs","repos_url":"https://api.github.com/users/roshan/repos","events_url":"https://api.github.com/users/roshan/events{/privacy}","received_events_url":"https://api.github.com/users/roshan/received_events","type":"User","site_admin":false},"repo":{"id":33912419,"name":"thrift","full_name":"roshan/thrift","owner":{"login":"roshan","id":7322596,"avatar_url":"https://avatars.githubusercontent.com/u/7322596?v=3","gravatar_id":"","url":"https://api.github.com/users/roshan","html_url":"https://github.com/roshan","followers_url":"https://api.github.com/users/roshan/followers","following_url":"https://api.github.com/users/roshan/following{/other_user}","gists_url":"https://api.github.com/users/roshan/gists{/gist_id}","starred_url":"https://api.github.com/users/roshan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roshan/subscriptions","organizations_url":"https://api.github.com/users/roshan/orgs","repos_url":"https://api.github.com/users/roshan/repos","events_url":"https://api.github.com/users/roshan/events{/privacy}","received_events_url":"https://api.github.com/users/roshan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/roshan/thrift","description":"Mirror of Apache Thrift","fork":true,"url":"https://api.github.com/repos/roshan/thrift","forks_url":"https://api.github.com/repos/roshan/thrift/forks","keys_url":"https://api.github.com/repos/roshan/thrift/keys{/key_id}","collaborators_url":"https://api.github.com/repos/roshan/thrift/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/roshan/thrift/teams","hooks_url":"https://api.github.com/repos/roshan/thrift/hooks","issue_events_url":"https://api.github.com/repos/roshan/thrift/issues/events{/number}","events_url":"https://api.github.com/repos/roshan/thrift/events","assignees_url":"https://api.github.com/repos/roshan/thrift/assignees{/user}","branches_url":"https://api.github.com/repos/roshan/thrift/branches{/branch}","tags_url":"https://api.github.com/repos/roshan/thrift/tags","blobs_url":"https://api.github.com/repos/roshan/thrift/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/roshan/thrift/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/roshan/thrift/git/refs{/sha}","trees_url":"https://api.github.com/repos/roshan/thrift/git/trees{/sha}","statuses_url":"https://api.github.com/repos/roshan/thrift/statuses/{sha}","languages_url":"https://api.github.com/repos/roshan/thrift/languages","stargazers_url":"https://api.github.com/repos/roshan/thrift/stargazers","contributors_url":"https://api.github.com/repos/roshan/thrift/contributors","subscribers_url":"https://api.github.com/repos/roshan/thrift/subscribers","subscription_url":"https://api.github.com/repos/roshan/thrift/subscription","commits_url":"https://api.github.com/repos/roshan/thrift/commits{/sha}","git_commits_url":"https://api.github.com/repos/roshan/thrift/git/commits{/sha}","comments_url":"https://api.github.com/repos/roshan/thrift/comments{/number}","issue_comment_url":"https://api.github.com/repos/roshan/thrift/issues/comments{/number}","contents_url":"https://api.github.com/repos/roshan/thrift/contents/{+path}","compare_url":"https://api.github.com/repos/roshan/thrift/compare/{base}...{head}","merges_url":"https://api.github.com/repos/roshan/thrift/merges","archive_url":"https://api.github.com/repos/roshan/thrift/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/roshan/thrift/downloads","issues_url":"https://api.github.com/repos/roshan/thrift/issues{/number}","pulls_url":"https://api.github.com/repos/roshan/thrift/pulls{/number}","milestones_url":"https://api.github.com/repos/roshan/thrift/milestones{/number}","notifications_url":"https://api.github.com/repos/roshan/thrift/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/roshan/thrift/labels{/name}","releases_url":"https://api.github.com/repos/roshan/thrift/releases{/id}","deployments_url":"https://api.github.com/repos/roshan/thrift/deployments","created_at":"2015-04-14T05:23:42Z","updated_at":"2015-04-14T05:23:47Z","pushed_at":"2016-02-13T06:20:47Z","git_url":"git://github.com/roshan/thrift.git","ssh_url":"git@github.com:roshan/thrift.git","clone_url":"https://github.com/roshan/thrift.git","svn_url":"https://github.com/roshan/thrift","homepage":"","size":15859,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"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":"apache:master","ref":"master","sha":"ac06704a0c62df9ca03782cb05b0f8cc05387a45","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":310611,"name":"thrift","full_name":"apache/thrift","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/thrift","description":"Mirror of Apache Thrift","fork":false,"url":"https://api.github.com/repos/apache/thrift","forks_url":"https://api.github.com/repos/apache/thrift/forks","keys_url":"https://api.github.com/repos/apache/thrift/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/thrift/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/thrift/teams","hooks_url":"https://api.github.com/repos/apache/thrift/hooks","issue_events_url":"https://api.github.com/repos/apache/thrift/issues/events{/number}","events_url":"https://api.github.com/repos/apache/thrift/events","assignees_url":"https://api.github.com/repos/apache/thrift/assignees{/user}","branches_url":"https://api.github.com/repos/apache/thrift/branches{/branch}","tags_url":"https://api.github.com/repos/apache/thrift/tags","blobs_url":"https://api.github.com/repos/apache/thrift/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/thrift/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/thrift/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/thrift/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/thrift/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/thrift/languages","stargazers_url":"https://api.github.com/repos/apache/thrift/stargazers","contributors_url":"https://api.github.com/repos/apache/thrift/contributors","subscribers_url":"https://api.github.com/repos/apache/thrift/subscribers","subscription_url":"https://api.github.com/repos/apache/thrift/subscription","commits_url":"https://api.github.com/repos/apache/thrift/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/thrift/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/thrift/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/thrift/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/thrift/contents/{+path}","compare_url":"https://api.github.com/repos/apache/thrift/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/thrift/merges","archive_url":"https://api.github.com/repos/apache/thrift/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/thrift/downloads","issues_url":"https://api.github.com/repos/apache/thrift/issues{/number}","pulls_url":"https://api.github.com/repos/apache/thrift/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/thrift/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/thrift/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/thrift/labels{/name}","releases_url":"https://api.github.com/repos/apache/thrift/releases{/id}","deployments_url":"https://api.github.com/repos/apache/thrift/deployments","created_at":"2009-09-18T08:00:17Z","updated_at":"2016-02-12T18:01:19Z","pushed_at":"2016-02-13T06:20:48Z","git_url":"git://github.com/apache/thrift.git","ssh_url":"git@github.com:apache/thrift.git","clone_url":"https://github.com/apache/thrift.git","svn_url":"https://github.com/apache/thrift","homepage":"","size":21975,"stargazers_count":2366,"watchers_count":2366,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1414,"mirror_url":"git://git.apache.org/thrift.git","open_issues_count":86,"forks":1414,"open_issues":86,"watchers":2366,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/thrift/pulls/448"},"html":{"href":"https://github.com/apache/thrift/pull/448"},"issue":{"href":"https://api.github.com/repos/apache/thrift/issues/448"},"comments":{"href":"https://api.github.com/repos/apache/thrift/issues/448/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/thrift/pulls/448/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/thrift/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/thrift/pulls/448/commits"},"statuses":{"href":"https://api.github.com/repos/apache/thrift/statuses/c79377cbbd0f0f14549714d8a71433d7f166eefe"}}}}