{"action":"created","issue":{"url":"https://api.github.com/repos/netty/netty/issues/3735","labels_url":"https://api.github.com/repos/netty/netty/issues/3735/labels{/name}","comments_url":"https://api.github.com/repos/netty/netty/issues/3735/comments","events_url":"https://api.github.com/repos/netty/netty/issues/3735/events","html_url":"https://github.com/netty/netty/pull/3735","id":73452101,"number":3735,"title":"ByteString and AsciiString equals/hashCode updates","user":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"Scottmitch","id":7562868,"avatar_url":"https://avatars.githubusercontent.com/u/7562868?v=3","gravatar_id":"","url":"https://api.github.com/users/Scottmitch","html_url":"https://github.com/Scottmitch","followers_url":"https://api.github.com/users/Scottmitch/followers","following_url":"https://api.github.com/users/Scottmitch/following{/other_user}","gists_url":"https://api.github.com/users/Scottmitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Scottmitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scottmitch/subscriptions","organizations_url":"https://api.github.com/users/Scottmitch/orgs","repos_url":"https://api.github.com/users/Scottmitch/repos","events_url":"https://api.github.com/users/Scottmitch/events{/privacy}","received_events_url":"https://api.github.com/users/Scottmitch/received_events","type":"User","site_admin":false},"milestone":null,"comments":11,"created_at":"2015-05-05T22:30:54Z","updated_at":"2015-05-06T19:39:59Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/netty/netty/pulls/3735","html_url":"https://github.com/netty/netty/pull/3735","diff_url":"https://github.com/netty/netty/pull/3735.diff","patch_url":"https://github.com/netty/netty/pull/3735.patch"},"body":"Motivation:\r\nThe ByteString class is often used in equality and hashCode operations. ByteString caches the hashCode after computed but case insensitive AsciiString hashCode operations are not cached.  The hash code algorithm we currently have is home grown and applies a mask of 31 onto every byte or character while generating the hash code which reduces the amount of bits each character contributes to the hash code from 8 down to 5. There is also an opportunity for improvement if two CharSequence objects are being used for equals/hashCode by using the underlying char[] (currently a toString() operation is being done).\r\n\r\nModifications:\r\n- Use a hash code algorithm which takes all the bits of each character into account.\r\n- Update ByteString and AsciiString to take advantage of the new equals/hashCode implementations.\r\n- Improve string equality algorithm for case sensitive and insensitive.\r\n- Consolidate equals/hashCode into an interface which can be easily upgraded or supplimented with UNSAFE in the future.\r\n- Correct bug in AsciiString static equals method which takes a CharSequence parameter.\r\n\r\nResult:\r\nByteString and AsciiString hashCode algorithm uses all bits from each character. AsciiString caches the case insensitive hashCode result. Equals operation has performance improvment when char[] is in use."},"comment":{"url":"https://api.github.com/repos/netty/netty/issues/comments/99583199","html_url":"https://github.com/netty/netty/pull/3735#issuecomment-99583199","issue_url":"https://api.github.com/repos/netty/netty/issues/3735","id":99583199,"user":{"login":"buchgr","id":1388179,"avatar_url":"https://avatars.githubusercontent.com/u/1388179?v=3","gravatar_id":"","url":"https://api.github.com/users/buchgr","html_url":"https://github.com/buchgr","followers_url":"https://api.github.com/users/buchgr/followers","following_url":"https://api.github.com/users/buchgr/following{/other_user}","gists_url":"https://api.github.com/users/buchgr/gists{/gist_id}","starred_url":"https://api.github.com/users/buchgr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buchgr/subscriptions","organizations_url":"https://api.github.com/users/buchgr/orgs","repos_url":"https://api.github.com/users/buchgr/repos","events_url":"https://api.github.com/users/buchgr/events{/privacy}","received_events_url":"https://api.github.com/users/buchgr/received_events","type":"User","site_admin":false},"created_at":"2015-05-06T19:39:59Z","updated_at":"2015-05-06T19:39:59Z","body":"> Are you looking for benchmarks that are not presented in #3735 (comment)? I can add benchmarks if desired (adding string benchmarks).\r\n\r\nwhere it shows that equals for `char[]` is faster now and in which scenarios (concrete classes) we can take advantage of this faster comparison.\r\n\r\n> Agreed. Either way I think the having 1 hashCode value for lower/upper case carries less weight now that we have ByteString and AsciiString. ByteString should detect these as differences.\r\n\r\nI don't really care. I have no evidence / reason to believe that the current hash code isn't good enough.\r\n\r\n> I think that may lead to a violation of the Object.hashCode() interface guarantees:\r\n> \r\n> ByteString a = new AsciiString(\"foo\");\r\n> ByteString b = new ByteString(\"foo\", CharsetUtil.US_ASCII);\r\n> \r\n> // At this point a.equals(b) will be true, but will a.hashCode() == b.hashCode()?\r\n\r\nWell if you override hashcode you would obviously also have to override equals.\r\n\r\n"}}