mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
binary serch when size > 16
This commit is contained in:
parent
2244e33943
commit
86686a99b9
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
"--gtest_filter=vm.c_module_get_set_attr"
|
||||
// "--gtest_filter=vm.c_module_get_set_attr"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -331,47 +331,44 @@ Arg* _obj_getProp(PikaObj* obj, char* name) {
|
||||
}
|
||||
}
|
||||
Hash method_hash = hash_time33(name);
|
||||
#define BINARY_SEARCH_ENABLE 1
|
||||
while (1) {
|
||||
if (prop == NULL) {
|
||||
break;
|
||||
}
|
||||
#if BINARY_SEARCH_ENABLE
|
||||
/* binary search */
|
||||
int size = prop->methodGroupCount;
|
||||
/* binary search */
|
||||
if (size == 0) {
|
||||
goto next;
|
||||
}
|
||||
int left = 0;
|
||||
int right = size - 1;
|
||||
int mid = 0;
|
||||
int i = 0;
|
||||
while (1) {
|
||||
i++;
|
||||
if (left > right) {
|
||||
break;
|
||||
if (size > 16) {
|
||||
int left = 0;
|
||||
int right = size - 1;
|
||||
int mid = 0;
|
||||
while (1) {
|
||||
if (left > right) {
|
||||
break;
|
||||
}
|
||||
mid = (right + left) >> 1;
|
||||
Arg* prop_this = (Arg*)(prop->methodGroup + mid);
|
||||
if (prop_this->name_hash == method_hash) {
|
||||
method = prop_this;
|
||||
goto exit;
|
||||
} else if (prop_this->name_hash < method_hash) {
|
||||
left = mid + 1;
|
||||
} else {
|
||||
right = mid - 1;
|
||||
}
|
||||
}
|
||||
mid = (right + left) >> 1;
|
||||
Arg* prop_this = (Arg*)(prop->methodGroup + mid);
|
||||
if (prop_this->name_hash == method_hash) {
|
||||
method = prop_this;
|
||||
goto exit;
|
||||
} else if (prop_this->name_hash < method_hash) {
|
||||
left = mid + 1;
|
||||
} else {
|
||||
right = mid - 1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (int i = 0; i < (int)prop->methodGroupCount; i++) {
|
||||
Arg* prop_this = (Arg*)(prop->methodGroup + i);
|
||||
if (prop_this->name_hash == method_hash) {
|
||||
method = prop_this;
|
||||
goto exit;
|
||||
} else {
|
||||
for (int i = 0; i < (int)prop->methodGroupCount; i++) {
|
||||
Arg* prop_this = (Arg*)(prop->methodGroup + i);
|
||||
if (prop_this->name_hash == method_hash) {
|
||||
method = prop_this;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
goto next;
|
||||
#endif
|
||||
next:
|
||||
prop = (NativeProperty*)prop->super;
|
||||
}
|
||||
|
@ -2,4 +2,4 @@
|
||||
#define PIKA_VERSION_MINOR 11
|
||||
#define PIKA_VERSION_MICRO 4
|
||||
|
||||
#define PIKA_EDIT_TIME "2022/10/10 21:37:18"
|
||||
#define PIKA_EDIT_TIME "2022/10/15 23:32:32"
|
||||
|
Loading…
x
Reference in New Issue
Block a user