Replace O(n) function lookup with O(1) hash map and fix memory leaks#146
Merged
Replace O(n) function lookup with O(1) hash map and fix memory leaks#146
Conversation
Co-authored-by: SIGMazer <88988252+SIGMazer@users.noreply.github.com>
…eaks Co-authored-by: SIGMazer <88988252+SIGMazer@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Identify and suggest improvements to slow code
Replace O(n) function lookup with O(1) hash map and fix memory leaks
Nov 12, 2025
Member
|
@leo-aa88 check this out :" |
Member
|
Member
|
LGTM |
leo-aa88
approved these changes
Nov 12, 2025
SIGMazer
approved these changes
Nov 12, 2025
SIGMazer
approved these changes
Nov 12, 2025
Member
|
@leo-aa88 can u approve this again |
leo-aa88
approved these changes
Nov 12, 2025
Member
|
@copilot u can merge the pr now |
Contributor
Author
I don't have permission to merge PRs directly. The PR can be merged by maintainers with write access through GitHub's interface. The PR is ready - all tests pass and it has been approved. |
Member
|
somehow i can't merge it can u do @leo-aa88 |
SIGMazer
approved these changes
Nov 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Function lookups used linear search through a linked list (
strcmpon every node), degrading performance with program size. Additionally, functions were created twice (parse + execute phases) causing memory leaks.Changes
Function storage
function_tablelinked list withfunction_maphash mapFunction.nextpointer from structget_function()now O(1) instead of O(n)Memory management
create_function()to prevent double-creationfree_function_table()to properly free all functionshm_free_shallow()for hash maps storing pointers to externally-managed memoryCode quality
strdup()withsafe_strdup()for consistent error handlingstrlen()results inadd_variable_to_scope()to avoid redundant calculationsExample
Before:
After:
Testing
All 63 unit tests and 69 valgrind memory tests pass with zero leaks detected.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.