Replace obj "reachable" with flags

This commit is contained in:
2022-11-22 16:23:03 -05:00
parent 5320c70dea
commit 7a2cbb2f26
2 changed files with 6 additions and 5 deletions

View File

@@ -83,6 +83,7 @@ struct ucl_object *ucl_special_create(struct ucl* ucl, ucl_lisp special)
static struct ucl_object* ucl_object_alloc(struct ucl* ucl) { static struct ucl_object* ucl_object_alloc(struct ucl* ucl) {
struct ucl_object *obj = ucl_arena_get(ucl->obj_arena); struct ucl_object *obj = ucl_arena_get(ucl->obj_arena);
assert(obj != NULL); assert(obj != NULL);
obj->flags = 0;
return obj; return obj;
} }
@@ -123,11 +124,11 @@ void ucl_object_delete(struct ucl* state, struct ucl_object *obj) {
} }
static void ucl_object_mark(struct ucl_object *obj) { static void ucl_object_mark(struct ucl_object *obj) {
if (obj == NULL || obj->reachable) { if (obj == NULL || obj->flags & UCL_OBJ_FLAG_REACHABLE) {
return; return;
} }
obj->reachable = 1; obj->flags |= 1;
if (obj->type == UCL_TYPE_CELL) { if (obj->type == UCL_TYPE_CELL) {
ucl_object_mark(obj->cell.car); ucl_object_mark(obj->cell.car);
ucl_object_mark(obj->cell.cdr); ucl_object_mark(obj->cell.cdr);
@@ -144,13 +145,13 @@ static void ucl_scope_mark(struct ucl_arena * arena, void *obj) {
static void ucl_gc_unmark(struct ucl_arena * arena, void *obj) { static void ucl_gc_unmark(struct ucl_arena * arena, void *obj) {
(void) arena; (void) arena;
struct ucl_object *object = (struct ucl_object *) obj; struct ucl_object *object = (struct ucl_object *) obj;
object->reachable = 0; object->flags &= ~UCL_OBJ_FLAG_REACHABLE;
} }
static void ucl_gc_sweep(struct ucl_arena * arena, void *obj) { static void ucl_gc_sweep(struct ucl_arena * arena, void *obj) {
(void) arena; (void) arena;
struct ucl_object *object = (struct ucl_object *) obj; struct ucl_object *object = (struct ucl_object *) obj;
if (object->reachable == 0) { if (!(object->flags &UCL_OBJ_FLAG_REACHABLE)) {
ucl_object_delete_internal(arena, object); ucl_object_delete_internal(arena, object);
} }
} }

View File

@@ -40,7 +40,7 @@ struct ucl_object {
ucl_lisp special; ucl_lisp special;
}; };
enum ucl_type type; enum ucl_type type;
char reachable; char flags;
}; };
struct ucl_scope { struct ucl_scope {