Skip to content

Refactor POPULAR_BABY_NAMES_2021 to use Rc<RefCell> instead of Arc<Mutex>#24

Merged
brndnmtthws merged 3 commits intobrndnmtthws:mainfrom
DannyCeb:main
Nov 27, 2025
Merged

Refactor POPULAR_BABY_NAMES_2021 to use Rc<RefCell> instead of Arc<Mutex>#24
brndnmtthws merged 3 commits intobrndnmtthws:mainfrom
DannyCeb:main

Conversation

@DannyCeb
Copy link
Contributor

Summary

This PR refactors the POPULAR_BABY_NAMES_2021 global variable to use Rc<RefCell<Vec<String>>> instead of Arc<Mutex<Option<Vec<String>>>>. Since the data is only accessed within a single thread, this change removes unnecessary synchronization overhead while preserving interior mutability.

Rationale

  • Rc<RefCell<T>> is more appropriate for single-threaded scenarios.
  • Simplifies the code and improves readability.
  • Keeps the behavior consistent with the original intent.

Notes

Most of the file was left untouched to maintain alignment with the book version.

@DannyCeb
Copy link
Contributor Author

Let me know if a comment in main.rs would be helpful to clarify this change as an errata or deviation.

@brndnmtthws
Copy link
Owner

The build error appears unrelated to your changes, and I fixed it in #26. If you merge or rebase against main, the build should pass now.

@brndnmtthws brndnmtthws merged commit 6f0eeb8 into brndnmtthws:main Nov 27, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants