From 974b1da8734c5a076ddba5ef21e568db7e3ec985 Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sun, 14 Dec 2025 01:35:13 +0100 Subject: [PATCH] Small optimizations --- PerfectNumbers.Core/BTree.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/PerfectNumbers.Core/BTree.cs b/PerfectNumbers.Core/BTree.cs index f14e3e5..e8ee580 100644 --- a/PerfectNumbers.Core/BTree.cs +++ b/PerfectNumbers.Core/BTree.cs @@ -39,7 +39,10 @@ public sealed class BTree() return; } - EnsureRoot(); + if (_nodeCount == 0) + { + EnsureRoot(); + } Node[] nodes = _nodes; if (smallCount > 0) @@ -116,24 +119,19 @@ public sealed class BTree() : 0u; } - [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] private void EnsureRoot() { - if (_nodeCount != 0) - { - return; - } - _nodes = new Node[DefaultCapacity]; _nodes[0] = new Node(); _nodeCount = 1; } - [MethodImpl(MethodImplOptions.AggressiveOptimization)] + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] private void InsertIntoTree(uint hash, TKey key, TValue value, int currentCount) { - var nodes = _nodes; - var currentIndex = 0; + Node[]? nodes = _nodes; + int currentIndex = 0; int depth = currentCount < ShallowTreeThreshold ? ShallowHashByteCount : HashByteCount; int nodeCount = _nodeCount;