Allow binary search for open methods. (#132)
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
// Generic guideline is that global hash is being used in global persistent
|
||||
// context, while local hashes are more local in scope.
|
||||
// Local hash.
|
||||
typedef uint64_t LocalHash;
|
||||
typedef int64_t LocalHash;
|
||||
// Hash of field name.
|
||||
typedef LocalHash FieldNameHash;
|
||||
// Hash of open method name.
|
||||
|
||||
@@ -1,10 +1,52 @@
|
||||
#include "Assert.h"
|
||||
#include "TypeInfo.h"
|
||||
|
||||
// If one shall use binary search when looking up methods and fields.
|
||||
// TODO: maybe select strategy basing on number of elements.
|
||||
#define USE_BINARY_SEARCH 0
|
||||
|
||||
extern "C" {
|
||||
#if USE_BINARY_SEARCH
|
||||
|
||||
int LookupFieldOffset(const TypeInfo* info, FieldNameHash nameSignature) {
|
||||
int bottom = 0;
|
||||
int top = info->fieldsCount_ - 1;
|
||||
|
||||
while (bottom <= top) {
|
||||
int middle = (bottom + top) / 2;
|
||||
if (info->fields_[middle].nameSignature_ < nameSignature)
|
||||
bottom = middle + 1;
|
||||
else if (info->fields_[middle].nameSignature_ == nameSignature)
|
||||
return info->fields_[middle].fieldOffset_;
|
||||
else
|
||||
top = middle - 1;
|
||||
}
|
||||
|
||||
RuntimeAssert(false, "Unknown field");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void* LookupOpenMethod(const TypeInfo* info, MethodNameHash nameSignature) {
|
||||
int bottom = 0;
|
||||
int top = info->openMethodsCount_ - 1;
|
||||
|
||||
while (bottom <= top) {
|
||||
int middle = (bottom + top) / 2;
|
||||
if (info->openMethods_[middle].nameSignature_ < nameSignature)
|
||||
bottom = middle + 1;
|
||||
else if (info->openMethods_[middle].nameSignature_ == nameSignature)
|
||||
return info->openMethods_[middle].methodEntryPoint_;
|
||||
else
|
||||
top = middle - 1;
|
||||
}
|
||||
|
||||
RuntimeAssert(false, "Unknown open method");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int LookupFieldOffset(const TypeInfo* info, FieldNameHash nameSignature) {
|
||||
// TODO: make it binary search?
|
||||
for (int i = 0; i < info->fieldsCount_; ++i) {
|
||||
if (info->fields_[i].nameSignature_ == nameSignature) {
|
||||
return info->fields_[i].fieldOffset_;
|
||||
@@ -15,7 +57,6 @@ int LookupFieldOffset(const TypeInfo* info, FieldNameHash nameSignature) {
|
||||
}
|
||||
|
||||
void* LookupOpenMethod(const TypeInfo* info, MethodNameHash nameSignature) {
|
||||
// TODO: make it binary search?
|
||||
for (int i = 0; i < info->openMethodsCount_; ++i) {
|
||||
if (info->openMethods_[i].nameSignature_ == nameSignature) {
|
||||
return info->openMethods_[i].methodEntryPoint_;
|
||||
@@ -25,4 +66,6 @@ void* LookupOpenMethod(const TypeInfo* info, MethodNameHash nameSignature) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user