Skip to content

Commit 6bf48ae

Browse files
Merge pull request #398 from MPCoreDeveloper/sonar/mechanical-cleanup-3
sonar: fix remaining mechanical issues (batch 3)
2 parents 1e4f4a6 + e8d7f21 commit 6bf48ae

2 files changed

Lines changed: 14 additions & 24 deletions

File tree

‎src/SharpCoreDB/DataStructures/Table.CRUD.cs‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,13 +2525,7 @@ this.storage is null ||
25252525
continue;
25262526
}
25272527

2528-
foreach (var colIdx in repoints)
2529-
{
2530-
if (!indexedColumns.Contains(colIdx))
2531-
{
2532-
indexedColumns.Add(colIdx);
2533-
}
2534-
}
2528+
indexedColumns.AddRange(repoints.Where(colIdx => !indexedColumns.Contains(colIdx)));
25352529
}
25362530

25372531
foreach (var colIdx in indexedColumns)
@@ -3745,7 +3739,7 @@ this.storage is null ||
37453739
/// whole-file snapshot. Returns null when the position/length is not fully contained in the
37463740
/// snapshot (caller falls back to the per-record read).
37473741
/// </summary>
3748-
private byte[]? TrySlicePayloadFromFile(byte[] wholeFile, long position)
3742+
private static byte[]? TrySlicePayloadFromFile(byte[] wholeFile, long position)
37493743
{
37503744
if (position < 0 || position + 4 > wholeFile.Length)
37513745
{
@@ -3973,12 +3967,9 @@ this.storage is null ||
39733967
{
39743968
// Transactional delete: buffer the physical offsets so the in-place marker is applied
39753969
// at COMMIT (see DeleteRecordsCore — rollback discards the buffer).
3976-
foreach (var position in positions)
3970+
foreach (var position in positions.Where(static position => position >= 0))
39773971
{
3978-
if (position >= 0)
3979-
{
3980-
this.storage.BufferTombstoneForCommit(DataFile, position);
3981-
}
3972+
this.storage.BufferTombstoneForCommit(DataFile, position);
39823973
}
39833974
}
39843975
else

‎src/SharpCoreDB/Services/SqlParser.Core.cs‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,20 +311,19 @@ public List<Dictionary<string, object>> ExecuteQuery(CachedQueryPlan plan, Dicti
311311
// B8: direct hash-index point lookup for `WHERE indexed_col = @param|literal`. This
312312
// skips building a WHERE string and re-parsing it inside SelectInternal — the single
313313
// biggest overhead difference vs the Direct API (FindByIndex) on point reads.
314-
if (TryResolveWhereValue(simple, parameters, out var whereValue) && whereValue is not null)
314+
if (TryResolveWhereValue(simple, parameters, out var whereValue) &&
315+
whereValue is not null &&
316+
table is DataStructures.Table concrete &&
317+
concrete.TrySelectIndexedPointLookup(simple.WhereColumn, whereValue, out var indexRows))
315318
{
316-
if (table is DataStructures.Table concrete &&
317-
concrete.TrySelectIndexedPointLookup(simple.WhereColumn, whereValue, out var indexRows))
318-
{
319-
if (simple.Offset.HasValue && simple.Offset.Value > 0)
320-
indexRows = [.. indexRows.Skip(simple.Offset.Value)];
319+
if (simple.Offset.HasValue && simple.Offset.Value > 0)
320+
indexRows = [.. indexRows.Skip(simple.Offset.Value)];
321321

322-
if (simple.Limit.HasValue && simple.Limit.Value > 0)
323-
indexRows = [.. indexRows.Take(simple.Limit.Value)];
322+
if (simple.Limit.HasValue && simple.Limit.Value > 0)
323+
indexRows = [.. indexRows.Take(simple.Limit.Value)];
324324

325-
results = concrete.DeduplicateByPrimaryKey(indexRows);
326-
return true;
327-
}
325+
results = concrete.DeduplicateByPrimaryKey(indexRows);
326+
return true;
328327
}
329328

330329
// Fallback: build the WHERE string exactly like the legacy binder and let the table

0 commit comments

Comments
 (0)