File tree Expand file tree Collapse file tree 4 files changed +42
-17
lines changed
main/java/com/trivago/fastutilconcurrentwrapper/io
test/java/com/trivago/fastutilconcurrentwrapper/io Expand file tree Collapse file tree 4 files changed +42
-17
lines changed Original file line number Diff line number Diff line change @@ -160,18 +160,24 @@ public boolean readBoolean () {
160
160
/// @see DataInputStream#readShort
161
161
/// (short)((read() << 8)|(read() & 0xFF))
162
162
@ Override
163
- public short readShort () {
164
- return (short )((read () << 8 )|(read () & 0xFF ));
163
+ public short readShort () {
164
+ short v = JBytes .DirectByteArrayAccess .getShort (buf , pos );
165
+ pos += 2 ;
166
+ return v ;
165
167
}
166
168
167
169
@ Override
168
170
public int readUnsignedShort () {
169
- return ((read () & 0xFF ) << 8 )|(read () & 0xFF );
171
+ int v = JBytes .DirectByteArrayAccess .getUnsignedShort (buf , pos );
172
+ pos += 2 ;
173
+ return v ;
170
174
}
171
175
172
176
@ Override
173
177
public char readChar () {
174
- return (char )(((read () & 0xFF ) << 8 )|(read () & 0xFF ));
178
+ char v = JBytes .DirectByteArrayAccess .getChar (buf , pos );
179
+ pos += 2 ;
180
+ return v ;
175
181
}
176
182
177
183
@ Override
@@ -205,12 +211,16 @@ public long readLong () {
205
211
206
212
@ Override
207
213
public float readFloat () {
208
- return Float .intBitsToFloat (readInt ());
214
+ float v = JBytes .DirectByteArrayAccess .getFloat (buf , pos );
215
+ pos += 4 ;
216
+ return v ;
209
217
}
210
218
211
219
@ Override
212
220
public double readDouble () {
213
- return Double .longBitsToDouble (readLong ());
221
+ double v = JBytes .DirectByteArrayAccess .getDouble (buf , pos );
222
+ pos += 8 ;
223
+ return v ;
214
224
}
215
225
216
226
@ Override @ Deprecated
Original file line number Diff line number Diff line change @@ -194,15 +194,19 @@ public void writeByte(int v) {
194
194
}
195
195
196
196
@ Override
197
- public void writeShort (int v ) {
198
- write (v >> 8 );
199
- write (v );
197
+ public void writeShort (int v ) {
198
+ grow (2 );
199
+ JBytes .DirectByteArrayAccess .setShort (buf , position , (short ) v );
200
+ position += 2 ;
201
+ if (count < position ) count = position ;
200
202
}
201
203
202
204
@ Override
203
- public void writeChar (int v ) {
204
- write (v >> 8 );
205
- write (v );
205
+ public void writeChar (int v ) {
206
+ grow (2 );
207
+ JBytes .DirectByteArrayAccess .setChar (buf , position , (char ) v );
208
+ position += 2 ;
209
+ if (count < position ) count = position ;
206
210
}
207
211
208
212
@ Override
@@ -234,12 +238,18 @@ public void writeLong (long v) {
234
238
235
239
@ Override
236
240
public void writeFloat (float v ) {
237
- writeInt (Float .floatToIntBits (v ));
241
+ grow (4 );
242
+ JBytes .DirectByteArrayAccess .setFloat (buf , position , v );
243
+ position += 4 ;
244
+ if (count < position ) count = position ;
238
245
}
239
246
240
247
@ Override
241
248
public void writeDouble (double v ) {
242
- writeLong (Double .doubleToLongBits (v ));
249
+ grow (8 );
250
+ JBytes .DirectByteArrayAccess .setDouble (buf , position , v );
251
+ position += 8 ;
252
+ if (count < position ) count = position ;
243
253
}
244
254
245
255
/**
Original file line number Diff line number Diff line change @@ -998,6 +998,8 @@ void _oos () throws IOException, ClassNotFoundException {
998
998
}
999
999
1000
1000
/// 500k: 5_760 ms, op/s=86_802
1001
+ /// VarHandle int&long: 2_333 ms, op/s=214_281
1002
+ /// all: 2_281, op/s=219_195
1001
1003
@ Test
1002
1004
void _benchmark () {
1003
1005
IntStream .range (0 , 2 ).forEach (__ ->{
Original file line number Diff line number Diff line change @@ -154,9 +154,12 @@ void testEOF () throws UTFDataFormatException {
154
154
assertEquals (-1 , r .readByte ());
155
155
assertEquals (0xff , r .readUnsignedByte ());
156
156
assertTrue (r .readBoolean ());//?
157
- assertEquals (-1 , r .readShort ());
158
- assertEquals (0xFFFF , r .readUnsignedShort ());
159
- assertEquals (0xFFFF , r .readChar ());
157
+ //assertEquals(-1, r.readShort());
158
+ assertThrows (ArrayIndexOutOfBoundsException .class , r ::readShort );
159
+ //assertEquals(0xFFFF, r.readUnsignedShort());
160
+ assertThrows (ArrayIndexOutOfBoundsException .class , r ::readUnsignedShort );
161
+ //assertEquals(0xFFFF, r.readChar());
162
+ assertThrows (ArrayIndexOutOfBoundsException .class , r ::readChar );
160
163
//assertEquals(-1, r.readInt());
161
164
assertThrows (ArrayIndexOutOfBoundsException .class , r ::readInt );
162
165
//assertEquals(-1, r.readLong());
You can’t perform that action at this time.
0 commit comments