mirror of
https://github.com/janet-lang/janet
synced 2026-10-09 09:11:40 +00:00
Make implementation match intention in comment.
We were doing forward instead of a backward search. This is slower, and for the unrootall case was also incorrect. unrootall was not commonly used but should still work as expected. Bug found by @pepe with help from Claude.
This commit is contained in:
+4
-5
@@ -645,9 +645,9 @@ static int janet_gc_idequals(Janet lhs, Janet rhs) {
|
||||
/* Remove a root value from the GC. This allows the gc to potentially reclaim
|
||||
* a value and all its children. */
|
||||
int janet_gcunroot(Janet root) {
|
||||
Janet *vtop = janet_vm.roots + janet_vm.root_count;
|
||||
/* Search from top to bottom as access is most likely LIFO */
|
||||
for (Janet *v = janet_vm.roots; v < vtop; v++) {
|
||||
for (Janet *v = janet_vm.roots + janet_vm.root_count; v > janet_vm.roots;) {
|
||||
v--;
|
||||
if (janet_gc_idequals(root, *v)) {
|
||||
*v = janet_vm.roots[--janet_vm.root_count];
|
||||
return 1;
|
||||
@@ -658,13 +658,12 @@ int janet_gcunroot(Janet root) {
|
||||
|
||||
/* Remove a root value from the GC. This sets the effective reference count to 0. */
|
||||
int janet_gcunrootall(Janet root) {
|
||||
Janet *vtop = janet_vm.roots + janet_vm.root_count;
|
||||
int ret = 0;
|
||||
/* Search from top to bottom as access is most likely LIFO */
|
||||
for (Janet *v = janet_vm.roots; v < vtop; v++) {
|
||||
for (Janet *v = janet_vm.roots + janet_vm.root_count; v > janet_vm.roots;) {
|
||||
v--;
|
||||
if (janet_gc_idequals(root, *v)) {
|
||||
*v = janet_vm.roots[--janet_vm.root_count];
|
||||
vtop--;
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user