@@ -1035,12 +1035,14 @@ public TItem FirstByPrimaryKey<TItem>(int loaderIndex, ConstraintInfo[] constrai
1035
1035
MemWriter keyBytes = new ( ) ;
1036
1036
keyBytes . WriteBlock ( _relationInfo . Prefix ) ;
1037
1037
1038
+ Span < byte > buffer = stackalloc byte [ 1024 ] ;
1039
+ var writer = MemWriter . CreateFromStackAllocatedSpan ( buffer ) ;
1038
1040
if ( orderers == null || orderers . Length == 0 )
1039
1041
{
1040
- using var enumerator = new RelationConstraintEnumerator < TItem > ( _transaction , _relationInfo , keyBytes ,
1042
+ using var enumerator = new RelationConstraintEnumerator < TItem > ( _transaction , _relationInfo , keyBytes , writer ,
1041
1043
loaderIndex , constraints ) ;
1042
1044
1043
- if ( enumerator . MoveNextInGather ( ) )
1045
+ if ( enumerator . MoveNext ( ) )
1044
1046
{
1045
1047
return enumerator . Current ! ;
1046
1048
}
@@ -1054,7 +1056,7 @@ public TItem FirstByPrimaryKey<TItem>(int loaderIndex, ConstraintInfo[] constrai
1054
1056
var primaryKeyFields = relationVersionInfo . PrimaryKeyFields . Span ;
1055
1057
var ordererIdxs = PrepareOrderers ( ref constraints , orderers , primaryKeyFields ) ;
1056
1058
1057
- using var enumerator = new RelationConstraintEnumerator < TItem > ( _transaction , _relationInfo , keyBytes ,
1059
+ using var enumerator = new RelationConstraintEnumerator < TItem > ( _transaction , _relationInfo , keyBytes , writer ,
1058
1060
loaderIndex , constraints ) ;
1059
1061
1060
1062
var sns = new SortNativeStorage ( true ) ;
@@ -1085,11 +1087,12 @@ public TItem FirstBySecondaryKey<TItem>(int loaderIndex, ConstraintInfo[] constr
1085
1087
keyBytes . WriteBlock ( _relationInfo . PrefixSecondary ) ;
1086
1088
var remappedSecondaryKeyIndex = RemapPrimeSK ( secondaryKeyIndex ) ;
1087
1089
keyBytes . WriteUInt8 ( ( byte ) remappedSecondaryKeyIndex ) ;
1088
-
1090
+ Span < byte > keyBuffer = stackalloc byte [ 1024 ] ;
1091
+ var writer = MemWriter . CreateFromStackAllocatedSpan ( keyBuffer ) ;
1089
1092
if ( orderers == null || orderers . Length == 0 )
1090
1093
{
1091
1094
using var enumerator = new RelationConstraintSecondaryKeyEnumerator < TItem > ( _transaction , _relationInfo ,
1092
- keyBytes ,
1095
+ keyBytes , writer ,
1093
1096
loaderIndex , constraints , remappedSecondaryKeyIndex , this ) ;
1094
1097
1095
1098
if ( enumerator . MoveNextInGather ( ) )
@@ -1108,7 +1111,7 @@ public TItem FirstBySecondaryKey<TItem>(int loaderIndex, ConstraintInfo[] constr
1108
1111
var ordererIdxs = PrepareOrderersSK ( ref constraints , orderers , fields , relationVersionInfo ) ;
1109
1112
1110
1113
using var enumerator = new RelationConstraintSecondaryKeyEnumerator < TItem > ( _transaction , _relationInfo ,
1111
- keyBytes ,
1114
+ keyBytes , writer ,
1112
1115
loaderIndex , constraints , remappedSecondaryKeyIndex , this ) ;
1113
1116
1114
1117
var sns = new SortNativeStorage ( true ) ;
@@ -1241,20 +1244,23 @@ int[] PrepareOrderers(ref ConstraintInfo[] constraints, IOrderer[] orderers,
1241
1244
return ( count , keySizes , valueSizes ) ;
1242
1245
}
1243
1246
1247
+ [ SkipLocalsInit ]
1244
1248
public ulong GatherByPrimaryKey < TItem > ( int loaderIndex , ConstraintInfo [ ] constraints , ICollection < TItem > target ,
1245
1249
long skip , long take , IOrderer [ ] ? orderers )
1246
1250
{
1247
- MemWriter keyBytes = new ( ) ;
1251
+ var keyBytes = MemWriter . CreateFromStackAllocatedSpan ( stackalloc byte [ 4096 ] ) ;
1248
1252
keyBytes . WriteBlock ( _relationInfo . Prefix ) ;
1249
1253
if ( skip < 0 )
1250
1254
{
1251
1255
take += skip ;
1252
1256
skip = 0 ;
1253
1257
}
1254
1258
1259
+ var writer = MemWriter . CreateFromStackAllocatedSpan ( stackalloc byte [ 1024 ] ) ;
1260
+
1255
1261
if ( orderers == null || orderers . Length == 0 )
1256
1262
{
1257
- using var enumerator = new RelationConstraintEnumerator < TItem > ( _transaction , _relationInfo , keyBytes ,
1263
+ using var enumerator = new RelationConstraintEnumerator < TItem > ( _transaction , _relationInfo , keyBytes , writer ,
1258
1264
loaderIndex , constraints ) ;
1259
1265
1260
1266
var count = 0ul ;
@@ -1281,7 +1287,7 @@ public ulong GatherByPrimaryKey<TItem>(int loaderIndex, ConstraintInfo[] constra
1281
1287
var primaryKeyFields = relationVersionInfo . PrimaryKeyFields . Span ;
1282
1288
var ordererIdxs = PrepareOrderers ( ref constraints , orderers , primaryKeyFields ) ;
1283
1289
1284
- using var enumerator = new RelationConstraintEnumerator < TItem > ( _transaction , _relationInfo , keyBytes ,
1290
+ using var enumerator = new RelationConstraintEnumerator < TItem > ( _transaction , _relationInfo , keyBytes , writer ,
1285
1291
loaderIndex , constraints ) ;
1286
1292
1287
1293
var sns = new SortNativeStorage ( false ) ;
@@ -1309,8 +1315,7 @@ public ulong GatherByPrimaryKey<TItem>(int loaderIndex, ConstraintInfo[] constra
1309
1315
public ulong GatherBySecondaryKey < TItem > ( int loaderIndex , ConstraintInfo [ ] constraints , ICollection < TItem > target ,
1310
1316
long skip , long take , uint secondaryKeyIndex , IOrderer [ ] ? orderers )
1311
1317
{
1312
- Span < byte > buf = stackalloc byte [ 4096 ] ;
1313
- var keyBytes = MemWriter . CreateFromStackAllocatedSpan ( buf ) ;
1318
+ var keyBytes = MemWriter . CreateFromStackAllocatedSpan ( stackalloc byte [ 4096 ] ) ;
1314
1319
keyBytes . WriteBlock ( _relationInfo . PrefixSecondary ) ;
1315
1320
var remappedSecondaryKeyIndex = RemapPrimeSK ( secondaryKeyIndex ) ;
1316
1321
keyBytes . WriteUInt8 ( ( byte ) remappedSecondaryKeyIndex ) ;
@@ -1319,11 +1324,11 @@ public ulong GatherBySecondaryKey<TItem>(int loaderIndex, ConstraintInfo[] const
1319
1324
take += skip ;
1320
1325
skip = 0 ;
1321
1326
}
1322
-
1327
+ var writer = MemWriter . CreateFromStackAllocatedSpan ( stackalloc byte [ 1024 ] ) ;
1323
1328
if ( orderers == null || orderers . Length == 0 )
1324
1329
{
1325
1330
using var enumerator = new RelationConstraintSecondaryKeyEnumerator < TItem > ( _transaction , _relationInfo ,
1326
- keyBytes ,
1331
+ keyBytes , writer ,
1327
1332
loaderIndex , constraints , remappedSecondaryKeyIndex , this ) ;
1328
1333
1329
1334
var count = 0ul ;
@@ -1352,7 +1357,7 @@ public ulong GatherBySecondaryKey<TItem>(int loaderIndex, ConstraintInfo[] const
1352
1357
var ordererIdxs = PrepareOrderersSK ( ref constraints , orderers , fields , relationVersionInfo ) ;
1353
1358
1354
1359
using var enumerator = new RelationConstraintSecondaryKeyEnumerator < TItem > ( _transaction , _relationInfo ,
1355
- keyBytes ,
1360
+ keyBytes , writer ,
1356
1361
loaderIndex , constraints , remappedSecondaryKeyIndex , this ) ;
1357
1362
1358
1363
var sns = new SortNativeStorage ( false ) ;
@@ -1424,7 +1429,7 @@ public IEnumerable<TItem> ScanByPrimaryKeyPrefix<TItem>(int loaderIndex, Constra
1424
1429
{
1425
1430
MemWriter keyBytes = new ( ) ;
1426
1431
keyBytes . WriteBlock ( _relationInfo . Prefix ) ;
1427
- return new RelationConstraintEnumerator < TItem > ( _transaction , _relationInfo , keyBytes ,
1432
+ return new RelationConstraintEnumerator < TItem > ( _transaction , _relationInfo , keyBytes , new MemWriter ( ) ,
1428
1433
loaderIndex , constraints ) ;
1429
1434
}
1430
1435
@@ -1435,7 +1440,7 @@ public IEnumerable<TItem> ScanBySecondaryKeyPrefix<TItem>(int loaderIndex, Const
1435
1440
keyBytes . WriteBlock ( _relationInfo . PrefixSecondary ) ;
1436
1441
var remappedSecondaryKeyIndex = RemapPrimeSK ( secondaryKeyIndex ) ;
1437
1442
keyBytes . WriteUInt8 ( ( byte ) remappedSecondaryKeyIndex ) ;
1438
- return new RelationConstraintSecondaryKeyEnumerator < TItem > ( _transaction , _relationInfo , keyBytes ,
1443
+ return new RelationConstraintSecondaryKeyEnumerator < TItem > ( _transaction , _relationInfo , keyBytes , new MemWriter ( ) ,
1439
1444
loaderIndex , constraints , remappedSecondaryKeyIndex , this ) ;
1440
1445
}
1441
1446
0 commit comments