@@ -615,7 +615,6 @@ public CompositeByteBuf removeComponent(int cIndex) { |
615 | 615 | Component comp = components[cIndex]; |
616 | 616 | if (lastAccessed == comp) { |
617 | 617 | lastAccessed = null; |
618 | | - lastAccessedIndex = 0; |
619 | 618 | } |
620 | 619 | comp.free(); |
621 | 620 | removeComp(cIndex); |
@@ -647,7 +646,6 @@ public CompositeByteBuf removeComponents(int cIndex, int numComponents) { |
647 | 646 | } |
648 | 647 | if (lastAccessed == c) { |
649 | 648 | lastAccessed = null; |
650 | | - lastAccessedIndex = 0; |
651 | 649 | } |
652 | 650 | c.free(); |
653 | 651 | } |
@@ -858,7 +856,6 @@ public CompositeByteBuf capacity(int newCapacity) { |
858 | 856 | } |
859 | 857 | } else if (newCapacity < oldCapacity) { |
860 | 858 | lastAccessed = null; |
861 | | - lastAccessedIndex = 0; |
862 | 859 | int i = size - 1; |
863 | 860 | for (int bytesToTrim = oldCapacity - newCapacity; i >= 0; i--) { |
864 | 861 | Component c = components[i]; |
@@ -955,36 +952,20 @@ public int toByteIndex(int cIndex) { |
955 | 952 | @Override |
956 | 953 | public byte getByte(int index) { |
957 | 954 | Component c = findComponent(index); |
958 | | - return c.abuf != null ? c.abuf._getByte(c.idx(index)) : c.buf.getByte(c.idx(index)); |
959 | | - } |
960 | | - |
961 | | - @Override |
962 | | - public byte readByte() { |
963 | | - checkReadableBytes(1); |
964 | | - int rIdx = readerIndex; |
965 | | - Component c = lastAccessed; |
966 | | - if (c == null) { |
967 | | - c = findIt(rIdx); |
968 | | - } else if (rIdx >= c.endOffset) { |
969 | | - c = findComponentForRead(rIdx); |
970 | | - } else if (rIdx < c.offset) { |
971 | | - c = findIt(rIdx); |
972 | | - } |
973 | | - readerIndex = rIdx + 1; |
974 | | - return c.abuf != null ? c.abuf._getByte(rIdx + c.adjustment) : c.buf.getByte(rIdx + c.adjustment); |
| 955 | + return c.buf.getByte(c.idx(index)); |
975 | 956 | } |
976 | 957 |
|
977 | 958 | @Override |
978 | 959 | protected byte _getByte(int index) { |
979 | 960 | Component c = findComponent0(index); |
980 | | - return c.abuf != null ? c.abuf._getByte(c.idx(index)) : c.buf.getByte(c.idx(index)); |
| 961 | + return c.buf.getByte(c.idx(index)); |
981 | 962 | } |
982 | 963 |
|
983 | 964 | @Override |
984 | 965 | protected short _getShort(int index) { |
985 | 966 | Component c = findComponent0(index); |
986 | 967 | if (index + 2 <= c.endOffset) { |
987 | | - return c.abuf != null ? c.abuf._getShort(c.idx(index)) : c.buf.getShort(c.idx(index)); |
| 968 | + return c.buf.getShort(c.idx(index)); |
988 | 969 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
989 | 970 | return (short) ((_getByte(index) & 0xff) << 8 | _getByte(index + 1) & 0xff); |
990 | 971 | } else { |
@@ -996,7 +977,7 @@ protected short _getShort(int index) { |
996 | 977 | protected short _getShortLE(int index) { |
997 | 978 | Component c = findComponent0(index); |
998 | 979 | if (index + 2 <= c.endOffset) { |
999 | | - return c.abuf != null ? c.abuf._getShortLE(c.idx(index)) : c.buf.getShortLE(c.idx(index)); |
| 980 | + return c.buf.getShortLE(c.idx(index)); |
1000 | 981 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1001 | 982 | return (short) (_getByte(index) & 0xff | (_getByte(index + 1) & 0xff) << 8); |
1002 | 983 | } else { |
@@ -1008,8 +989,7 @@ protected short _getShortLE(int index) { |
1008 | 989 | protected int _getUnsignedMedium(int index) { |
1009 | 990 | Component c = findComponent0(index); |
1010 | 991 | if (index + 3 <= c.endOffset) { |
1011 | | - return c.abuf != null ? c.abuf._getUnsignedMedium(c.idx(index)) |
1012 | | - : c.buf.getUnsignedMedium(c.idx(index)); |
| 992 | + return c.buf.getUnsignedMedium(c.idx(index)); |
1013 | 993 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1014 | 994 | return (_getShort(index) & 0xffff) << 8 | _getByte(index + 2) & 0xff; |
1015 | 995 | } else { |
@@ -1021,8 +1001,7 @@ protected int _getUnsignedMedium(int index) { |
1021 | 1001 | protected int _getUnsignedMediumLE(int index) { |
1022 | 1002 | Component c = findComponent0(index); |
1023 | 1003 | if (index + 3 <= c.endOffset) { |
1024 | | - return c.abuf != null ? c.abuf._getUnsignedMediumLE(c.idx(index)) |
1025 | | - : c.buf.getUnsignedMediumLE(c.idx(index)); |
| 1004 | + return c.buf.getUnsignedMediumLE(c.idx(index)); |
1026 | 1005 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1027 | 1006 | return _getShortLE(index) & 0xffff | (_getByte(index + 2) & 0xff) << 16; |
1028 | 1007 | } else { |
@@ -1034,7 +1013,7 @@ protected int _getUnsignedMediumLE(int index) { |
1034 | 1013 | protected int _getInt(int index) { |
1035 | 1014 | Component c = findComponent0(index); |
1036 | 1015 | if (index + 4 <= c.endOffset) { |
1037 | | - return c.abuf != null ? c.abuf._getInt(c.idx(index)) : c.buf.getInt(c.idx(index)); |
| 1016 | + return c.buf.getInt(c.idx(index)); |
1038 | 1017 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1039 | 1018 | return (_getShort(index) & 0xffff) << 16 | _getShort(index + 2) & 0xffff; |
1040 | 1019 | } else { |
@@ -1046,7 +1025,7 @@ protected int _getInt(int index) { |
1046 | 1025 | protected int _getIntLE(int index) { |
1047 | 1026 | Component c = findComponent0(index); |
1048 | 1027 | if (index + 4 <= c.endOffset) { |
1049 | | - return c.abuf != null ? c.abuf._getIntLE(c.idx(index)) : c.buf.getIntLE(c.idx(index)); |
| 1028 | + return c.buf.getIntLE(c.idx(index)); |
1050 | 1029 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1051 | 1030 | return _getShortLE(index) & 0xffff | (_getShortLE(index + 2) & 0xffff) << 16; |
1052 | 1031 | } else { |
@@ -1058,7 +1037,7 @@ protected int _getIntLE(int index) { |
1058 | 1037 | protected long _getLong(int index) { |
1059 | 1038 | Component c = findComponent0(index); |
1060 | 1039 | if (index + 8 <= c.endOffset) { |
1061 | | - return c.abuf != null ? c.abuf._getLong(c.idx(index)) : c.buf.getLong(c.idx(index)); |
| 1040 | + return c.buf.getLong(c.idx(index)); |
1062 | 1041 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1063 | 1042 | return (_getInt(index) & 0xffffffffL) << 32 | _getInt(index + 4) & 0xffffffffL; |
1064 | 1043 | } else { |
@@ -1070,7 +1049,7 @@ protected long _getLong(int index) { |
1070 | 1049 | protected long _getLongLE(int index) { |
1071 | 1050 | Component c = findComponent0(index); |
1072 | 1051 | if (index + 8 <= c.endOffset) { |
1073 | | - return c.abuf != null ? c.abuf._getLongLE(c.idx(index)) : c.buf.getLongLE(c.idx(index)); |
| 1052 | + return c.buf.getLongLE(c.idx(index)); |
1074 | 1053 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1075 | 1054 | return _getIntLE(index) & 0xffffffffL | (_getIntLE(index + 4) & 0xffffffffL) << 32; |
1076 | 1055 | } else { |
@@ -1201,22 +1180,14 @@ public CompositeByteBuf getBytes(int index, OutputStream out, int length) throws |
1201 | 1180 | @Override |
1202 | 1181 | public CompositeByteBuf setByte(int index, int value) { |
1203 | 1182 | Component c = findComponent(index); |
1204 | | - if (c.abuf != null) { |
1205 | | - c.abuf._setByte(c.idx(index), value); |
1206 | | - } else { |
1207 | | - c.buf.setByte(c.idx(index), value); |
1208 | | - } |
| 1183 | + c.buf.setByte(c.idx(index), value); |
1209 | 1184 | return this; |
1210 | 1185 | } |
1211 | 1186 |
|
1212 | 1187 | @Override |
1213 | 1188 | protected void _setByte(int index, int value) { |
1214 | 1189 | Component c = findComponent0(index); |
1215 | | - if (c.abuf != null) { |
1216 | | - c.abuf._setByte(c.idx(index), value); |
1217 | | - } else { |
1218 | | - c.buf.setByte(c.idx(index), value); |
1219 | | - } |
| 1190 | + c.buf.setByte(c.idx(index), value); |
1220 | 1191 | } |
1221 | 1192 |
|
1222 | 1193 | @Override |
@@ -1230,11 +1201,7 @@ public CompositeByteBuf setShort(int index, int value) { |
1230 | 1201 | protected void _setShort(int index, int value) { |
1231 | 1202 | Component c = findComponent0(index); |
1232 | 1203 | if (index + 2 <= c.endOffset) { |
1233 | | - if (c.abuf != null) { |
1234 | | - c.abuf._setShort(c.idx(index), value); |
1235 | | - } else { |
1236 | | - c.buf.setShort(c.idx(index), value); |
1237 | | - } |
| 1204 | + c.buf.setShort(c.idx(index), value); |
1238 | 1205 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1239 | 1206 | _setByte(index, (byte) (value >>> 8)); |
1240 | 1207 | _setByte(index + 1, (byte) value); |
@@ -1248,11 +1215,7 @@ protected void _setShort(int index, int value) { |
1248 | 1215 | protected void _setShortLE(int index, int value) { |
1249 | 1216 | Component c = findComponent0(index); |
1250 | 1217 | if (index + 2 <= c.endOffset) { |
1251 | | - if (c.abuf != null) { |
1252 | | - c.abuf._setShortLE(c.idx(index), value); |
1253 | | - } else { |
1254 | | - c.buf.setShortLE(c.idx(index), value); |
1255 | | - } |
| 1218 | + c.buf.setShortLE(c.idx(index), value); |
1256 | 1219 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1257 | 1220 | _setByte(index, (byte) value); |
1258 | 1221 | _setByte(index + 1, (byte) (value >>> 8)); |
@@ -1273,11 +1236,7 @@ public CompositeByteBuf setMedium(int index, int value) { |
1273 | 1236 | protected void _setMedium(int index, int value) { |
1274 | 1237 | Component c = findComponent0(index); |
1275 | 1238 | if (index + 3 <= c.endOffset) { |
1276 | | - if (c.abuf != null) { |
1277 | | - c.abuf._setMedium(c.idx(index), value); |
1278 | | - } else { |
1279 | | - c.buf.setMedium(c.idx(index), value); |
1280 | | - } |
| 1239 | + c.buf.setMedium(c.idx(index), value); |
1281 | 1240 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1282 | 1241 | _setShort(index, (short) (value >> 8)); |
1283 | 1242 | _setByte(index + 2, (byte) value); |
@@ -1291,11 +1250,7 @@ protected void _setMedium(int index, int value) { |
1291 | 1250 | protected void _setMediumLE(int index, int value) { |
1292 | 1251 | Component c = findComponent0(index); |
1293 | 1252 | if (index + 3 <= c.endOffset) { |
1294 | | - if (c.abuf != null) { |
1295 | | - c.abuf._setMediumLE(c.idx(index), value); |
1296 | | - } else { |
1297 | | - c.buf.setMediumLE(c.idx(index), value); |
1298 | | - } |
| 1253 | + c.buf.setMediumLE(c.idx(index), value); |
1299 | 1254 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1300 | 1255 | _setShortLE(index, (short) value); |
1301 | 1256 | _setByte(index + 2, (byte) (value >>> 16)); |
@@ -1316,11 +1271,7 @@ public CompositeByteBuf setInt(int index, int value) { |
1316 | 1271 | protected void _setInt(int index, int value) { |
1317 | 1272 | Component c = findComponent0(index); |
1318 | 1273 | if (index + 4 <= c.endOffset) { |
1319 | | - if (c.abuf != null) { |
1320 | | - c.abuf._setInt(c.idx(index), value); |
1321 | | - } else { |
1322 | | - c.buf.setInt(c.idx(index), value); |
1323 | | - } |
| 1274 | + c.buf.setInt(c.idx(index), value); |
1324 | 1275 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1325 | 1276 | _setShort(index, (short) (value >>> 16)); |
1326 | 1277 | _setShort(index + 2, (short) value); |
@@ -1334,11 +1285,7 @@ protected void _setInt(int index, int value) { |
1334 | 1285 | protected void _setIntLE(int index, int value) { |
1335 | 1286 | Component c = findComponent0(index); |
1336 | 1287 | if (index + 4 <= c.endOffset) { |
1337 | | - if (c.abuf != null) { |
1338 | | - c.abuf._setIntLE(c.idx(index), value); |
1339 | | - } else { |
1340 | | - c.buf.setIntLE(c.idx(index), value); |
1341 | | - } |
| 1288 | + c.buf.setIntLE(c.idx(index), value); |
1342 | 1289 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1343 | 1290 | _setShortLE(index, (short) value); |
1344 | 1291 | _setShortLE(index + 2, (short) (value >>> 16)); |
@@ -1359,11 +1306,7 @@ public CompositeByteBuf setLong(int index, long value) { |
1359 | 1306 | protected void _setLong(int index, long value) { |
1360 | 1307 | Component c = findComponent0(index); |
1361 | 1308 | if (index + 8 <= c.endOffset) { |
1362 | | - if (c.abuf != null) { |
1363 | | - c.abuf._setLong(c.idx(index), value); |
1364 | | - } else { |
1365 | | - c.buf.setLong(c.idx(index), value); |
1366 | | - } |
| 1309 | + c.buf.setLong(c.idx(index), value); |
1367 | 1310 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1368 | 1311 | _setInt(index, (int) (value >>> 32)); |
1369 | 1312 | _setInt(index + 4, (int) value); |
@@ -1377,11 +1320,7 @@ protected void _setLong(int index, long value) { |
1377 | 1320 | protected void _setLongLE(int index, long value) { |
1378 | 1321 | Component c = findComponent0(index); |
1379 | 1322 | if (index + 8 <= c.endOffset) { |
1380 | | - if (c.abuf != null) { |
1381 | | - c.abuf._setLongLE(c.idx(index), value); |
1382 | | - } else { |
1383 | | - c.buf.setLongLE(c.idx(index), value); |
1384 | | - } |
| 1323 | + c.buf.setLongLE(c.idx(index), value); |
1385 | 1324 | } else if (order() == ByteOrder.BIG_ENDIAN) { |
1386 | 1325 | _setIntLE(index, (int) value); |
1387 | 1326 | _setIntLE(index + 4, (int) (value >>> 32)); |
@@ -1674,7 +1613,6 @@ public ByteBuf internalComponentAtOffset(int offset) { |
1674 | 1613 |
|
1675 | 1614 | // weak cache - check it first when looking for component |
1676 | 1615 | private Component lastAccessed; |
1677 | | - private int lastAccessedIndex; |
1678 | 1616 |
|
1679 | 1617 | private Component findComponent(int offset) { |
1680 | 1618 | Component la = lastAccessed; |
@@ -1694,22 +1632,6 @@ private Component findComponent0(int offset) { |
1694 | 1632 | return findIt(offset); |
1695 | 1633 | } |
1696 | 1634 |
|
1697 | | - /** |
1698 | | - * Sequential-read fast path: try the next component(s) before falling back to binary search. |
1699 | | - */ |
1700 | | - private Component findComponentForRead(int offset) { |
1701 | | - int cc = componentCount; |
1702 | | - for (int next = lastAccessedIndex + 1; next < cc; next++) { |
1703 | | - Component c = components[next]; |
1704 | | - if (offset < c.endOffset) { |
1705 | | - lastAccessed = c; |
1706 | | - lastAccessedIndex = next; |
1707 | | - return c; |
1708 | | - } |
1709 | | - } |
1710 | | - return findIt(offset); |
1711 | | - } |
1712 | | - |
1713 | 1635 | private Component findIt(int offset) { |
1714 | 1636 | for (int low = 0, high = componentCount; low <= high;) { |
1715 | 1637 | int mid = low + high >>> 1; |
@@ -1724,7 +1646,6 @@ private Component findIt(int offset) { |
1724 | 1646 | high = mid - 1; |
1725 | 1647 | } else { |
1726 | 1648 | lastAccessed = c; |
1727 | | - lastAccessedIndex = mid; |
1728 | 1649 | return c; |
1729 | 1650 | } |
1730 | 1651 | } |
@@ -1864,7 +1785,6 @@ private void consolidate0(int cIndex, int numComponents) { |
1864 | 1785 | components[i].transferTo(consolidated); |
1865 | 1786 | } |
1866 | 1787 | lastAccessed = null; |
1867 | | - lastAccessedIndex = 0; |
1868 | 1788 | removeCompRange(cIndex + 1, endCIndex); |
1869 | 1789 | components[cIndex] = newComponent(consolidated, 0); |
1870 | 1790 | if (cIndex != 0 || numComponents != componentCount) { |
@@ -1889,7 +1809,6 @@ public CompositeByteBuf discardReadComponents() { |
1889 | 1809 | components[i].free(); |
1890 | 1810 | } |
1891 | 1811 | lastAccessed = null; |
1892 | | - lastAccessedIndex = 0; |
1893 | 1812 | clearComps(); |
1894 | 1813 | setIndex(0, 0); |
1895 | 1814 | adjustMarkers(readerIndex); |
@@ -1912,7 +1831,6 @@ public CompositeByteBuf discardReadComponents() { |
1912 | 1831 | Component la = lastAccessed; |
1913 | 1832 | if (la != null && la.endOffset <= readerIndex) { |
1914 | 1833 | lastAccessed = null; |
1915 | | - lastAccessedIndex = 0; |
1916 | 1834 | } |
1917 | 1835 | removeCompRange(0, firstComponentId); |
1918 | 1836 |
|
@@ -1939,7 +1857,6 @@ public CompositeByteBuf discardReadBytes() { |
1939 | 1857 | components[i].free(); |
1940 | 1858 | } |
1941 | 1859 | lastAccessed = null; |
1942 | | - lastAccessedIndex = 0; |
1943 | 1860 | clearComps(); |
1944 | 1861 | setIndex(0, 0); |
1945 | 1862 | adjustMarkers(readerIndex); |
@@ -1971,7 +1888,6 @@ public CompositeByteBuf discardReadBytes() { |
1971 | 1888 | Component la = lastAccessed; |
1972 | 1889 | if (la != null && la.endOffset <= readerIndex) { |
1973 | 1890 | lastAccessed = null; |
1974 | | - lastAccessedIndex = 0; |
1975 | 1891 | } |
1976 | 1892 |
|
1977 | 1893 | removeCompRange(0, firstComponentId); |
@@ -1997,7 +1913,6 @@ public String toString() { |
1997 | 1913 | private static final class Component { |
1998 | 1914 | final ByteBuf srcBuf; // the originally added buffer |
1999 | 1915 | final ByteBuf buf; // srcBuf unwrapped zero or more times |
2000 | | - final AbstractByteBuf abuf; // buf cast to AbstractByteBuf, or null if not an instance |
2001 | 1916 |
|
2002 | 1917 | int srcAdjustment; // index of the start of this CompositeByteBuf relative to srcBuf |
2003 | 1918 | int adjustment; // index of the start of this CompositeByteBuf relative to buf |
@@ -2012,7 +1927,6 @@ private static final class Component { |
2012 | 1927 | this.srcBuf = srcBuf; |
2013 | 1928 | this.srcAdjustment = srcOffset - offset; |
2014 | 1929 | this.buf = buf; |
2015 | | - this.abuf = buf instanceof AbstractByteBuf ? (AbstractByteBuf) buf : null; |
2016 | 1930 | this.adjustment = bufOffset - offset; |
2017 | 1931 | this.offset = offset; |
2018 | 1932 | this.endOffset = offset + len; |
|