Migrate to stb_ds for hashes and dynamic arrays#83
Merged
Conversation
Replace khash-backed StringMap with stb_ds hash maps for ROM aliasing. stb_ds provides a simpler, more widely-used single-header library with type-safe macros and automatic key management via sh_new_strdup(). Changes: - Add workspace/all/vendor/stb/stb_ds.h from nothings/stb - Add stb_ds_impl.c for single-TU implementation - Migrate launcher_map.c to use MapEntry* with stb_ds macros - Migrate launcher_emu_cache.c (uses NULL values for presence-only) - Export Map_free() for clean API - Delete stringmap.c/h and vendor/khash/
Remove the custom Array wrapper type in favor of using stb_ds dynamic arrays directly. This follows the same pattern as the previous StringMap to stb_ds migration. Changes: - Delete collections.h/c (Array type no longer needed) - Update Entry**, Recent**, Directory** to use stb_ds directly - Add -I vendor/stb to all makefiles for clean includes - Update all source files to use #include "stb_ds.h" - Update tests to use arrpush/arrlen/arrfree macros - Fix makefile.dev: add stb_ds_impl.c, launcher_emu_cache.c Migration pattern applied throughout: - Array* arr = Array_new() → T** arr = NULL - Array_push(arr, item) → arrpush(arr, item) - arr->count → arrlen(arr) - arr->items[i] → arr[i] - Array_free(arr) → arrfree(arr)
Continues the stb_ds migration by converting two more custom data structures: - LauncherPathStack: Replace capacity/count wrapper struct with simple typedef to stb_ds dynamic array. Simplifies push/pop to single-line macro calls. - LauncherDirScanResult: Consolidate parallel arrays (paths, is_dirs) into single struct array. Cleaner iteration and memory management.
There was a problem hiding this comment.
Pull request overview
This PR migrates the codebase from custom Array data structures and khash-based StringMap to Sean Barrett's stb_ds single-header library for dynamic arrays and hash tables. The migration affects data structure usage throughout the launcher, replacing:
- Custom
Arraytype with stb_ds dynamic arrays (e.g.,Entry**instead ofArray*) StringMap(khash-backed) with stb_ds string hash maps (MapEntry*)- Manual memory management with stb_ds automatic growth
Key Changes:
- Adds stb_ds.h v0.67 vendor library with implementation file
- Removes khash.h, collections.h/c, stringmap.h/c, and their test file
- Migrates all dynamic array and hash map usage to stb_ds APIs
- Updates 40+ files including core launcher logic, tests, and build system
Reviewed changes
Copilot reviewed 40 out of 43 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| workspace/all/vendor/stb/stb_ds.h | Added stb_ds v0.67 library (1895 lines, vendor file) |
| workspace/all/vendor/khash/khash.h | Removed khash library (was used for StringMap) |
| workspace/all/vendor/README.md | Updated to document stb_ds instead of khash |
| workspace/all/common/stb_ds_impl.c | Added implementation file for stb_ds |
| workspace/all/common/collections.[ch] | Removed custom Array implementation |
| workspace/all/common/stringmap.[ch] | Removed StringMap (khash wrapper) |
| workspace/all/common/utils.[ch] | Made prefixMatch/suffixMatch const-correct |
| workspace/all/launcher/*.c | Migrated to stb_ds dynamic arrays and hash maps |
| workspace/all/player/player_archive.c | Removed unnecessary casts |
| tests/unit/all/**/*.c | Updated tests for stb_ds APIs |
| build files | Updated includes and source lists |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.