Skip to content

Commit

Permalink
[callbacks] Adjust cb_size in new_id() instead of every call site (ze…
Browse files Browse the repository at this point in the history
…phyrproject-rtos#1378)

Signed-off-by: Geoff Gustafson <[email protected]>
  • Loading branch information
grgustaf authored and Jimmy Huang committed Jul 21, 2017
1 parent 331e23b commit fceee73
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/zjs_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ static zjs_callback_id new_id(void)
while (cb_map[id] != NULL) {
id++;
}
if (id >= cb_size) {
cb_size = id + 1;
}
return id;
}

Expand Down Expand Up @@ -309,10 +312,6 @@ zjs_callback_id add_callback_list_priv(jerry_value_t js_func,
new_cb->func_list[0] = jerry_acquire_value(js_func);
cb_map[new_cb->id] = new_cb;

if (new_cb->id >= cb_size - 1) {
cb_size++;
}

#ifdef DEBUG_BUILD
set_info_string(cb_map[new_cb->id]->creator, file, func);
#endif
Expand Down Expand Up @@ -355,9 +354,6 @@ zjs_callback_id add_callback_priv(jerry_value_t js_func,

// Add callback to list
cb_map[new_cb->id] = new_cb;
if (new_cb->id >= cb_size - 1) {
cb_size++;
}

DBG_PRINT("adding new callback id %d, js_func=%u, once=%u\n", new_cb->id,
new_cb->js_func, once);
Expand Down Expand Up @@ -515,9 +511,6 @@ zjs_callback_id zjs_add_c_callback(void *handle, zjs_c_callback_func callback)

// Add callback to list
cb_map[new_cb->id] = new_cb;
if (new_cb->id >= cb_size - 1) {
cb_size++;
}

DBG_PRINT("adding new C callback id %d\n", new_cb->id);
UNLOCK();
Expand Down

0 comments on commit fceee73

Please sign in to comment.