@@ -175,10 +175,7 @@ public unsafe long PeekLong()
175
175
}
176
176
else if ( _block . End - _index >= sizeof ( long ) )
177
177
{
178
- fixed ( byte * ptr = & _block . Array [ _index ] )
179
- {
180
- return * ( long * ) ( ptr ) ;
181
- }
178
+ return * ( long * ) ( _block . DataFixedPtr + _index ) ;
182
179
}
183
180
else if ( _block . Next == null )
184
181
{
@@ -194,17 +191,9 @@ public unsafe long PeekLong()
194
191
return - 1 ;
195
192
}
196
193
197
- long blockLong ;
198
- fixed ( byte * ptr = & _block . Array [ _block . End - sizeof ( long ) ] )
199
- {
200
- blockLong = * ( long * ) ( ptr ) ;
201
- }
194
+ var blockLong = * ( long * ) ( _block . DataFixedPtr + _block . End - sizeof ( long ) ) ;
202
195
203
- long nextLong ;
204
- fixed ( byte * ptr = & _block . Next . Array [ _block . Next . Start ] )
205
- {
206
- nextLong = * ( long * ) ( ptr ) ;
207
- }
196
+ var nextLong = * ( long * ) ( _block . Next . DataFixedPtr + _block . Next . Start ) ;
208
197
209
198
return ( blockLong >> ( sizeof ( long ) - blockBytes ) * 8 ) | ( nextLong << ( sizeof ( long ) - nextBytes ) * 8 ) ;
210
199
}
@@ -266,22 +255,20 @@ public unsafe int Seek(ref Vector<byte> byte0Vector)
266
255
#if ! DEBUG
267
256
}
268
257
#endif
269
- fixed ( byte * ptr = & block. Array [ index ] )
258
+
259
+ var pCurrent = ( block . DataFixedPtr + index ) ;
260
+ var pEnd = pCurrent + following ;
261
+ do
270
262
{
271
- var pCurrent = ptr ;
272
- var pEnd = pCurrent + following ;
273
- do
263
+ if ( * pCurrent == byte0 )
274
264
{
275
- if ( * pCurrent == byte0 )
276
- {
277
- _block = block ;
278
- _index = index ;
279
- return byte0;
280
- }
281
- pCurrent ++ ;
282
- index ++ ;
283
- } while ( pCurrent < pEnd ) ;
284
- }
265
+ _block = block ;
266
+ _index = index ;
267
+ return byte0 ;
268
+ }
269
+ pCurrent ++ ;
270
+ index ++ ;
271
+ } while ( pCurrent < pEnd ) ;
285
272
286
273
following = 0 ;
287
274
break ;
@@ -367,28 +354,25 @@ public unsafe int Seek(ref Vector<byte> byte0Vector, ref Vector<byte> byte1Vecto
367
354
#if ! DEBUG
368
355
}
369
356
#endif
370
- fixed ( byte * ptr = & block . Array [ index ] )
357
+ var pCurrent = ( block . DataFixedPtr + index ) ;
358
+ var pEnd = pCurrent + following ;
359
+ do
371
360
{
372
- var pCurrent = ptr;
373
- var pEnd = pCurrent + following;
374
- do
361
+ if ( * pCurrent == byte0 )
375
362
{
376
- if ( * pCurrent == byte0 )
377
- {
378
- _block = block ;
379
- _index = index ;
380
- return byte0;
381
- }
382
- if ( * pCurrent == byte1 )
383
- {
384
- _block = block ;
385
- _index = index ;
386
- return byte1;
387
- }
388
- pCurrent ++ ;
389
- index ++ ;
390
- } while ( pCurrent != pEnd ) ;
391
- }
363
+ _block = block ;
364
+ _index = index ;
365
+ return byte0 ;
366
+ }
367
+ if ( * pCurrent == byte1 )
368
+ {
369
+ _block = block ;
370
+ _index = index ;
371
+ return byte1 ;
372
+ }
373
+ pCurrent ++ ;
374
+ index ++ ;
375
+ } while ( pCurrent != pEnd ) ;
392
376
393
377
following = 0 ;
394
378
break ;
@@ -502,34 +486,31 @@ public unsafe int Seek(ref Vector<byte> byte0Vector, ref Vector<byte> byte1Vecto
502
486
#if ! DEBUG
503
487
}
504
488
#endif
505
- fixed ( byte * ptr = & block . Array [ index ] )
489
+ var pCurrent = ( block . DataFixedPtr + index ) ;
490
+ var pEnd = pCurrent + following ;
491
+ do
506
492
{
507
- var pCurrent = ptr;
508
- var pEnd = pCurrent + following;
509
- do
493
+ if ( * pCurrent == byte0 )
510
494
{
511
- if ( * pCurrent == byte0 )
512
- {
513
- _block = block ;
514
- _index = index ;
515
- return byte0;
516
- }
517
- if ( * pCurrent == byte1 )
518
- {
519
- _block = block ;
520
- _index = index ;
521
- return byte1;
522
- }
523
- if ( * pCurrent == byte2 )
524
- {
525
- _block = block ;
526
- _index = index ;
527
- return byte2;
528
- }
529
- pCurrent ++ ;
530
- index ++ ;
531
- } while ( pCurrent != pEnd ) ;
532
- }
495
+ _block = block ;
496
+ _index = index ;
497
+ return byte0 ;
498
+ }
499
+ if ( * pCurrent == byte1 )
500
+ {
501
+ _block = block ;
502
+ _index = index ;
503
+ return byte1 ;
504
+ }
505
+ if ( * pCurrent == byte2 )
506
+ {
507
+ _block = block ;
508
+ _index = index ;
509
+ return byte2 ;
510
+ }
511
+ pCurrent ++ ;
512
+ index ++ ;
513
+ } while ( pCurrent != pEnd ) ;
533
514
534
515
following = 0 ;
535
516
break ;
@@ -808,30 +789,25 @@ public unsafe void CopyFromAscii(string data)
808
789
bytesLeftInBlockMinusSpan = bytesLeftInBlock - 3 ;
809
790
}
810
791
811
- fixed ( byte * pOutput = & block . Data . Array [ block . End ] )
792
+ var output = ( block . DataFixedPtr + block . End ) ;
793
+ var copied = 0 ;
794
+ for ( ; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan ; copied += 4 )
812
795
{
813
- //this line is needed to allow output be an register var
814
- var output = pOutput;
815
-
816
- var copied = 0 ;
817
- for ( ; input < inputEndMinusSpan && copied < bytesLeftInBlockMinusSpan ; copied += 4 )
818
- {
819
- * ( output ) = ( byte ) * ( input) ;
820
- * ( output + 1 ) = ( byte ) * ( input + 1 ) ;
821
- * ( output + 2 ) = ( byte ) * ( input + 2 ) ;
822
- * ( output + 3 ) = ( byte ) * ( input + 3 ) ;
823
- output += 4 ;
824
- input += 4 ;
825
- }
826
- for ( ; input < inputEnd && copied < bytesLeftInBlock; copied++ )
827
- {
828
- * ( output++ ) = ( byte ) * ( input++ ) ;
829
- }
830
-
831
- blockIndex += copied;
832
- bytesLeftInBlockMinusSpan -= copied;
833
- bytesLeftInBlock -= copied;
796
+ * ( output ) = ( byte ) * ( input ) ;
797
+ * ( output + 1 ) = ( byte ) * ( input + 1 ) ;
798
+ * ( output + 2 ) = ( byte ) * ( input + 2 ) ;
799
+ * ( output + 3 ) = ( byte ) * ( input + 3 ) ;
800
+ output += 4 ;
801
+ input += 4 ;
834
802
}
803
+ for ( ; input < inputEnd && copied < bytesLeftInBlock ; copied ++ )
804
+ {
805
+ * ( output ++ ) = ( byte ) * ( input ++ ) ;
806
+ }
807
+
808
+ blockIndex += copied ;
809
+ bytesLeftInBlockMinusSpan -= copied ;
810
+ bytesLeftInBlock -= copied ;
835
811
}
836
812
}
837
813
0 commit comments