Skip to content

Commit c3340cb

Browse files
jeesup0103jhpark816
authored andcommitted
INTERNAL: Change DFS traverse order in set and map
1 parent e395870 commit c3340cb

File tree

2 files changed

+23
-45
lines changed

2 files changed

+23
-45
lines changed

engines/default/coll_map.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -497,30 +497,19 @@ static int do_map_elem_traverse_dfs_bycnt(map_meta_info *info, map_hash_node *no
497497
int hidx;
498498
int fcnt = 0; /* found count */
499499

500-
if (node->tot_hash_cnt > 0) {
501-
map_hash_node *child_node;
502-
int rcnt; /* request count */
503-
for (hidx = 0; hidx < MAP_HASHTAB_SIZE; hidx++) {
504-
if (node->hcnt[hidx] == -1) {
505-
child_node = (map_hash_node *)node->htab[hidx];
506-
rcnt = (count > 0 ? (count - fcnt) : 0);
507-
fcnt += do_map_elem_traverse_dfs_bycnt(info, child_node, rcnt, delete,
508-
(elem_array==NULL ? NULL : &elem_array[fcnt]), cause);
509-
if (delete) {
510-
if (child_node->tot_hash_cnt == 0 &&
511-
child_node->tot_elem_cnt < (MAP_MAX_HASHCHAIN_SIZE/2)) {
512-
do_map_node_unlink(info, node, hidx);
513-
}
500+
for (hidx = 0; hidx < MAP_HASHTAB_SIZE; hidx++) {
501+
if (node->hcnt[hidx] == -1) {
502+
map_hash_node *child_node = (map_hash_node *)node->htab[hidx];
503+
int rcnt = (count > 0 ? (count - fcnt) : 0);
504+
fcnt += do_map_elem_traverse_dfs_bycnt(info, child_node, rcnt, delete,
505+
(elem_array==NULL ? NULL : &elem_array[fcnt]), cause);
506+
if (delete) {
507+
if (child_node->tot_hash_cnt == 0 &&
508+
child_node->tot_elem_cnt < (MAP_MAX_HASHCHAIN_SIZE/2)) {
509+
do_map_node_unlink(info, node, hidx);
514510
}
515-
if (count > 0 && fcnt >= count)
516-
return fcnt;
517511
}
518-
}
519-
}
520-
assert(count == 0 || fcnt < count);
521-
522-
for (hidx = 0; hidx < MAP_HASHTAB_SIZE; hidx++) {
523-
if (node->hcnt[hidx] > 0) {
512+
} else if (node->hcnt[hidx] > 0) {
524513
map_elem_item *elem = node->htab[hidx];
525514
while (elem != NULL) {
526515
if (elem_array) {
@@ -532,8 +521,8 @@ static int do_map_elem_traverse_dfs_bycnt(map_meta_info *info, map_hash_node *no
532521
if (count > 0 && fcnt >= count) break;
533522
elem = (delete ? node->htab[hidx] : elem->next);
534523
}
535-
if (count > 0 && fcnt >= count) break;
536524
}
525+
if (count > 0 && fcnt >= count) break;
537526
}
538527
return fcnt;
539528
}

engines/default/coll_set.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -493,30 +493,19 @@ static int do_set_elem_traverse_dfs(set_meta_info *info, set_hash_node *node,
493493
int hidx;
494494
int fcnt = 0; /* found count */
495495

496-
if (node->tot_hash_cnt > 0) {
497-
set_hash_node *child_node;
498-
int rcnt; /* request count */
499-
for (hidx = 0; hidx < SET_HASHTAB_SIZE; hidx++) {
500-
if (node->hcnt[hidx] == -1) {
501-
child_node = (set_hash_node *)node->htab[hidx];
502-
rcnt = (count > 0 ? (count - fcnt) : 0);
503-
fcnt += do_set_elem_traverse_dfs(info, child_node, rcnt, delete,
496+
for (hidx = 0; hidx < SET_HASHTAB_SIZE; hidx++) {
497+
if (node->hcnt[hidx] == -1) {
498+
set_hash_node *child_node = (set_hash_node *)node->htab[hidx];
499+
int rcnt = (count > 0 ? (count - fcnt) : 0);
500+
fcnt += do_set_elem_traverse_dfs(info, child_node, rcnt, delete,
504501
(elem_array==NULL ? NULL : &elem_array[fcnt]));
505-
if (delete) {
506-
if (child_node->tot_hash_cnt == 0 &&
507-
child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)) {
508-
do_set_node_unlink(info, node, hidx);
509-
}
502+
if (delete) {
503+
if (child_node->tot_hash_cnt == 0 &&
504+
child_node->tot_elem_cnt < (SET_MAX_HASHCHAIN_SIZE/2)) {
505+
do_set_node_unlink(info, node, hidx);
510506
}
511-
if (count > 0 && fcnt >= count)
512-
return fcnt;
513507
}
514-
}
515-
}
516-
assert(count == 0 || fcnt < count);
517-
518-
for (hidx = 0; hidx < SET_HASHTAB_SIZE; hidx++) {
519-
if (node->hcnt[hidx] > 0) {
508+
} else if (node->hcnt[hidx] > 0) {
520509
set_elem_item *elem = node->htab[hidx];
521510
while (elem != NULL) {
522511
if (elem_array) {
@@ -530,8 +519,8 @@ static int do_set_elem_traverse_dfs(set_meta_info *info, set_hash_node *node,
530519
if (count > 0 && fcnt >= count) break;
531520
elem = (delete ? node->htab[hidx] : elem->next);
532521
}
533-
if (count > 0 && fcnt >= count) break;
534522
}
523+
if (count > 0 && fcnt >= count) break;
535524
}
536525
return fcnt;
537526
}

0 commit comments

Comments
 (0)