@@ -169,21 +169,16 @@ int getIpv4Start() {
169
169
*/
170
170
public <T > DatabaseRecord <T > getRecord (InetAddress ipAddress , Class <T > cls )
171
171
throws IOException {
172
- ByteBuffer buffer = this .getBufferHolder ().get ();
173
172
174
173
byte [] rawAddress = ipAddress .getAddress ();
175
174
176
- int bitLength = rawAddress .length * 8 ;
177
- int record = this .startNode (bitLength );
178
- int nodeCount = this .metadata .getNodeCount ();
175
+ int [] traverseResult = traverseTree (rawAddress , rawAddress .length * 8 );
179
176
180
- int pl = 0 ;
181
- for (; pl < bitLength && record < nodeCount ; pl ++) {
182
- int b = 0xFF & rawAddress [pl / 8 ];
183
- int bit = 1 & (b >> 7 - (pl % 8 ));
184
- record = this .readNode (buffer , record , bit );
185
- }
177
+ int pl = traverseResult [1 ];
178
+ int record = traverseResult [0 ];
186
179
180
+ int nodeCount = this .metadata .getNodeCount ();
181
+ ByteBuffer buffer = this .getBufferHolder ().get ();
187
182
T dataRecord = null ;
188
183
if (record > nodeCount ) {
189
184
// record is a data pointer
@@ -317,7 +312,7 @@ public <T> Networks<T> networksWithin(
317
312
prefixLength += 96 ;
318
313
}
319
314
320
- int [] traverseResult = this .traverseTree (ipBytes , 0 , prefixLength );
315
+ int [] traverseResult = this .traverseTree (ipBytes , prefixLength );
321
316
int node = traverseResult [0 ];
322
317
int prefix = traverseResult [1 ];
323
318
@@ -335,22 +330,24 @@ public <T> Networks<T> networksWithin(
335
330
* @param bitCount The prefix.
336
331
* @return int[]
337
332
*/
338
- private int [] traverseTree (byte [] ip , int node , int bitCount )
333
+ private int [] traverseTree (byte [] ip , int bitCount )
339
334
throws ClosedDatabaseException , InvalidDatabaseException {
340
- int nodeCount = this .metadata .getNodeCount ();
341
- int i = 0 ;
342
-
343
335
ByteBuffer buffer = this .getBufferHolder ().get ();
336
+ int bitLength = ip .length * 8 ;
337
+ int record = this .startNode (bitLength );
338
+ int nodeCount = this .metadata .getNodeCount ();
344
339
345
- for (; i < bitCount && node < nodeCount ; i ++) {
346
- int bit = 1 & (ip [i >> 3 ] >> (7 - (i % 8 )));
340
+ int i = 0 ;
341
+ for (; i < bitCount && record < nodeCount ; i ++) {
342
+ int b = 0xFF & ip [i / 8 ];
343
+ int bit = 1 & (b >> 7 - (i % 8 ));
347
344
348
345
// bit:0 -> left record.
349
346
// bit:1 -> right record.
350
- node = this .readNode (buffer , node , bit );
347
+ record = this .readNode (buffer , record , bit );
351
348
}
352
349
353
- return new int []{node , i };
350
+ return new int []{record , i };
354
351
}
355
352
356
353
int readNode (ByteBuffer buffer , int nodeNumber , int index )
0 commit comments