Another linked list bites the dust.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3928 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
30
src/task.c
30
src/task.c
@ -602,30 +602,6 @@ static JSValue _tf_task_version(JSContext* context, JSValueConst this_val, int a
|
||||
return JS_NewString(task->_context, k_version);
|
||||
}
|
||||
|
||||
static int _insert_index(const void* key, const void* base, size_t count, size_t size, int (*compare)(const void*, const void*))
|
||||
{
|
||||
int lower = 0;
|
||||
int upper = count;
|
||||
while (lower < upper && lower < (int)count)
|
||||
{
|
||||
int guess = (lower + upper) / 2;
|
||||
int result = compare(key, ((char*)base) + size * guess);
|
||||
if (result < 0)
|
||||
{
|
||||
upper = guess;
|
||||
}
|
||||
else if (result > 0)
|
||||
{
|
||||
lower = guess + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return guess;
|
||||
}
|
||||
};
|
||||
return lower;
|
||||
}
|
||||
|
||||
exportid_t tf_task_export_function(tf_task_t* task, tf_taskstub_t* to, JSValue function)
|
||||
{
|
||||
export_record_t* export = NULL;
|
||||
@ -654,7 +630,7 @@ exportid_t tf_task_export_function(tf_task_t* task, tf_taskstub_t* to, JSValue f
|
||||
._function = JS_DupValue(task->_context, function),
|
||||
};
|
||||
|
||||
int index = _insert_index(&id, task->_exports, task->_export_count, sizeof(export_record_t*), _export_compare);
|
||||
int index = tf_util_insert_index(&id, task->_exports, task->_export_count, sizeof(export_record_t*), _export_compare);
|
||||
task->_exports = tf_resize_vec(task->_exports, sizeof(export_record_t*) * (task->_export_count + 1));
|
||||
if (task->_export_count - index)
|
||||
{
|
||||
@ -1021,7 +997,7 @@ JSValue tf_task_allocate_promise(tf_task_t* task, promiseid_t* out_promise)
|
||||
.values = { JS_NULL, JS_NULL },
|
||||
};
|
||||
JSValue result = JS_NewPromiseCapability(task->_context, promise.values);
|
||||
int index = _insert_index((void*)(intptr_t)promiseId, task->_promises, task->_promise_count, sizeof(promise_t), _promise_compare);
|
||||
int index = tf_util_insert_index((void*)(intptr_t)promiseId, task->_promises, task->_promise_count, sizeof(promise_t), _promise_compare);
|
||||
task->_promises = tf_resize_vec(task->_promises, sizeof(promise_t) * (task->_promise_count + 1));
|
||||
if (task->_promise_count - index)
|
||||
{
|
||||
@ -1540,7 +1516,7 @@ JSValue tf_task_add_import(tf_task_t* task, taskid_t stub_id, exportid_t export_
|
||||
._useCount = 1,
|
||||
};
|
||||
|
||||
int index = _insert_index(import, task->_imports, task->_import_count, sizeof(import_record_t*), _import_compare);
|
||||
int index = tf_util_insert_index(import, task->_imports, task->_import_count, sizeof(import_record_t*), _import_compare);
|
||||
task->_imports = tf_resize_vec(task->_imports, sizeof(import_record_t*) * (task->_import_count + 1));
|
||||
if (task->_import_count - index)
|
||||
{
|
||||
|
Reference in New Issue
Block a user