fix: EntityCollection iterator O(n²) → O(n) with 100× speedup (closes #159)
Problem: EntityCollection iterator used index-based access on std::list, causing O(n) traversal per element access (O(n²) total for iteration). Root cause: Each call to next() started from begin() and advanced index steps: std::advance(l_begin, self->index-1); // O(index) for linked list! Solution: - Store actual std::list iterators (current, end) instead of index - Increment iterator directly in next() - O(1) operation - Cache Entity and Iterator type lookups to avoid repeated dict lookups Benchmark results (2,000 entities): - Before: 13.577ms via EntityCollection - After: 0.131ms via EntityCollection - Speedup: 103× 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
fcc0376f31
commit
8f2407b518
3 changed files with 39 additions and 31 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -26,6 +26,7 @@ mcrogueface.github.io
|
|||
scripts/
|
||||
tcod_reference
|
||||
.archive
|
||||
.mcp.json
|
||||
|
||||
# Keep important documentation and tests
|
||||
!CLAUDE.md
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue