NEO-59: address code review follow-ups
Simplify GetDefinitionsInIdOrder to iterate key-value pairs directly, avoiding the intermediate sorted-keys array and second dictionary lookup.pull/94/head
parent
dc66b5cef4
commit
1e1ca5519c
|
|
@ -33,16 +33,16 @@ None.
|
||||||
|
|
||||||
## Nits
|
## Nits
|
||||||
|
|
||||||
- `GetDefinitionsInIdOrder()` iterates `.Keys` to build a sorted array then does a second dictionary lookup per key. Iterating key-value pairs directly is slightly more idiomatic and avoids the double lookup:
|
- ~~`GetDefinitionsInIdOrder()` iterates `.Keys` to build a sorted array then does a second dictionary lookup per key. Iterating key-value pairs directly is slightly more idiomatic and avoids the double lookup:~~
|
||||||
|
|
||||||
```csharp
|
~~```csharp~~
|
||||||
return catalog.NodesById
|
~~return catalog.NodesById~~
|
||||||
.OrderBy(kv => kv.Key, StringComparer.Ordinal)
|
~~ .OrderBy(kv => kv.Key, StringComparer.Ordinal)~~
|
||||||
.Select(kv => kv.Value)
|
~~ .Select(kv => kv.Value)~~
|
||||||
.ToList();
|
~~ .ToList();~~
|
||||||
```
|
~~```~~
|
||||||
|
|
||||||
The current form matches `ItemDefinitionRegistry` exactly, so consistency may outweigh the change. No action required.
|
~~The current form matches `ItemDefinitionRegistry` exactly, so consistency may outweigh the change. No action required.~~ Done.
|
||||||
|
|
||||||
- The null-id and unknown-id tests each build a fully populated `nodes`/`yields` dictionary even though the exercised code paths exit before those entries are touched. Consistent with `ItemDefinitionRegistryTests` — no action required.
|
- The null-id and unknown-id tests each build a fully populated `nodes`/`yields` dictionary even though the exercised code paths exit before those entries are touched. Consistent with `ItemDefinitionRegistryTests` — no action required.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,15 +44,9 @@ public sealed class ResourceNodeDefinitionRegistry(ResourceNodeCatalog catalog)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IReadOnlyList<ResourceNodeDefRow> GetDefinitionsInIdOrder()
|
public IReadOnlyList<ResourceNodeDefRow> GetDefinitionsInIdOrder() =>
|
||||||
{
|
catalog.NodesById
|
||||||
var ids = catalog.NodesById.Keys.OrderBy(k => k, StringComparer.Ordinal).ToArray();
|
.OrderBy(kv => kv.Key, StringComparer.Ordinal)
|
||||||
var list = new List<ResourceNodeDefRow>(ids.Length);
|
.Select(kv => kv.Value)
|
||||||
foreach (var id in ids)
|
.ToList();
|
||||||
{
|
|
||||||
list.Add(catalog.NodesById[id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue