{"action":"created","issue":{"url":"https://api.github.com/repos/netty/netty/issues/3306","labels_url":"https://api.github.com/repos/netty/netty/issues/3306/labels{/name}","comments_url":"https://api.github.com/repos/netty/netty/issues/3306/comments","events_url":"https://api.github.com/repos/netty/netty/issues/3306/events","html_url":"https://github.com/netty/netty/issues/3306","id":53407374,"number":3306,"title":"Improve detection for algorithms which behave differently for multiple underlying buffers ","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":[{"url":"https://api.github.com/repos/netty/netty/labels/improvement","name":"improvement","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/netty/netty/milestones/109","labels_url":"https://api.github.com/repos/netty/netty/milestones/109/labels","id":918308,"number":109,"title":"4.0.26.Final","description":null,"creator":{"login":"trustin","id":173918,"avatar_url":"https://avatars.githubusercontent.com/u/173918?v=3","gravatar_id":"","url":"https://api.github.com/users/trustin","html_url":"https://github.com/trustin","followers_url":"https://api.github.com/users/trustin/followers","following_url":"https://api.github.com/users/trustin/following{/other_user}","gists_url":"https://api.github.com/users/trustin/gists{/gist_id}","starred_url":"https://api.github.com/users/trustin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trustin/subscriptions","organizations_url":"https://api.github.com/users/trustin/orgs","repos_url":"https://api.github.com/users/trustin/repos","events_url":"https://api.github.com/users/trustin/events{/privacy}","received_events_url":"https://api.github.com/users/trustin/received_events","type":"User","site_admin":false},"open_issues":54,"closed_issues":1,"state":"open","created_at":"2014-12-31T07:43:52Z","updated_at":"2015-01-06T08:34:33Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2015-01-05T15:31:04Z","updated_at":"2015-01-06T14:28:51Z","closed_at":null,"body":"PR https://github.com/netty/netty/pull/3266 demonstrated a use case which behaves differently if a ByteBuf has multiple internal NIO buffers.  One way to currently detect this condition is done [here](https://github.com/netty/netty/blob/4.0/handler/src/main/java/io/netty/handler/ssl/SslHandler.java#L616):\r\n\r\n```java\r\nif (!(in instanceof CompositeByteBuf) && in.nioBufferCount() == 1) {...}\r\n```\r\n\r\nIt is suggested that a new method be added to the ByteBuf interface to detect if multiple NIO buffers are being maintained.  This suggestion will avoid the following pitfalls of the current approach:\r\n1. Design health - It is not ideal to have assumptions based upon class hierarchy of an interface known through out code.  In this case the `ByteBuf` interface is being used and `instanceof CompositeByteBuf` is being done.  At least [this case](https://github.com/netty/netty/blob/4.0/handler/src/main/java/io/netty/handler/ssl/SslHandler.java#L616) could be simplified with the addition of a new method, and the assumption is the concept is generic enough where other parts of the code should also be able to take advantage.\r\n2. Performance benefit - It is not always necessary to get the full count of internal NIO buffers.  There is no guarantee that the implementations of `nioBufferCount()` are caching the result, and thus this call may require iteration and re-computation of the full count.\r\n"},"comment":{"url":"https://api.github.com/repos/netty/netty/issues/comments/68871394","html_url":"https://github.com/netty/netty/issues/3306#issuecomment-68871394","issue_url":"https://api.github.com/repos/netty/netty/issues/3306","id":68871394,"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},"created_at":"2015-01-06T14:28:51Z","updated_at":"2015-01-06T14:28:51Z","body":"@trustin @normanmaurer - Let me know what you think.  If we decide this is an improvement and select an approach I can put together a PR.  During this process I will investigate other cases where `instaceof CompositeByteBuf` is used. "}}