[ https://issues.apache.org/jira/browse/DRILL-5488?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul Rogers updated DRILL-5488: ------------------------------- Description: Consider this code in a generated fixed-width vector, such as UInt4Vector: {code} @Override public void setValueCount(int valueCount) { ... final int idx = (VALUE_WIDTH * valueCount); ... VectorTrimmer.trim(data, idx); data.writerIndex(valueCount * VALUE_WIDTH); } {code} Consider the {{trim()}} method: {code} public class VectorTrimmer { ... public static void trim(ByteBuf data, int idx) { data.writerIndex(idx); if (data instanceof DrillBuf) { // data.capacity(idx); data.writerIndex(idx); } } } {code} This method is called {{trim}}, but it actually sets the writer index in the buffer (though we never use that index.) Since all buffers we use are {{DrillBuf}}, the if-statement is a no-op: we simply set the writer index twice. But, notice that the {{setValueCount()}} method itself calls the same {{writerIndex()}} method, so it is actually being called three times. It seems this code can simply be discarded: it is called from only two places; neither of which end up using the writer index. was: Consider this code in a generated fixed-width vector, such as UInt4Vector: {code} @Override public void setValueCount(int valueCount) { ... final int idx = (VALUE_WIDTH * valueCount); ... VectorTrimmer.trim(data, idx); data.writerIndex(valueCount * VALUE_WIDTH); } {code} Consider the {{trim()}} method: {code} public class VectorTrimmer { ... public static void trim(ByteBuf data, int idx) { data.writerIndex(idx); if (data instanceof DrillBuf) { // data.capacity(idx); data.writerIndex(idx); } } } {code} This method is called {{trim}}, but it actually sets the writer index in the buffer (though we never use that index.) Since all buffers we use are {{DrillBuf}}, the if-statement is a no-op: we simply set the writer index twice. It seems this code can simply be discarded: it is called from only two places; neither of which end up using the writer index. > Useless code in VectorTrimmer > ----------------------------- > > Key: DRILL-5488 > URL: https://issues.apache.org/jira/browse/DRILL-5488 > Project: Apache Drill > Issue Type: Bug > Affects Versions: 1.10.0 > Reporter: Paul Rogers > Priority: Trivial > > Consider this code in a generated fixed-width vector, such as UInt4Vector: > {code} > @Override > public void setValueCount(int valueCount) { > ... > final int idx = (VALUE_WIDTH * valueCount); > ... > VectorTrimmer.trim(data, idx); > data.writerIndex(valueCount * VALUE_WIDTH); > } > {code} > Consider the {{trim()}} method: > {code} > public class VectorTrimmer { > ... > public static void trim(ByteBuf data, int idx) { > data.writerIndex(idx); > if (data instanceof DrillBuf) { > // data.capacity(idx); > data.writerIndex(idx); > } > } > } > {code} > This method is called {{trim}}, but it actually sets the writer index in the > buffer (though we never use that index.) Since all buffers we use are > {{DrillBuf}}, the if-statement is a no-op: we simply set the writer index > twice. > But, notice that the {{setValueCount()}} method itself calls the same > {{writerIndex()}} method, so it is actually being called three times. > It seems this code can simply be discarded: it is called from only two > places; neither of which end up using the writer index. -- This message was sent by Atlassian JIRA (v6.3.15#6346)