|
#include "methodcache.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
MethodCache_t* rava_methodcache_create(void) {
|
|
MethodCache_t* cache = malloc(sizeof(MethodCache_t));
|
|
if (cache) {
|
|
memset(cache, 0, sizeof(MethodCache_t));
|
|
}
|
|
return cache;
|
|
}
|
|
|
|
void rava_methodcache_destroy(MethodCache_t* cache) {
|
|
if (cache) free(cache);
|
|
}
|
|
|
|
RavaMethod_t* rava_methodcache_lookup(MethodCache_t* cache,
|
|
const char* classname,
|
|
const char* methodname) {
|
|
if (!cache || !classname || !methodname) return NULL;
|
|
|
|
uint32_t class_hash = rava_methodcache_hash(classname);
|
|
uint32_t method_hash = rava_methodcache_hash(methodname);
|
|
uint32_t idx = (class_hash ^ method_hash) & RAVA_METHOD_CACHE_MASK;
|
|
|
|
MethodCacheEntry_t* entry = &cache->entries[idx];
|
|
|
|
if (entry->class_hash == class_hash &&
|
|
entry->method_hash == method_hash &&
|
|
entry->method != NULL) {
|
|
return entry->method;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void rava_methodcache_insert(MethodCache_t* cache,
|
|
const char* classname,
|
|
const char* methodname,
|
|
RavaMethod_t* method) {
|
|
if (!cache || !classname || !methodname) return;
|
|
|
|
uint32_t class_hash = rava_methodcache_hash(classname);
|
|
uint32_t method_hash = rava_methodcache_hash(methodname);
|
|
uint32_t idx = (class_hash ^ method_hash) & RAVA_METHOD_CACHE_MASK;
|
|
|
|
MethodCacheEntry_t* entry = &cache->entries[idx];
|
|
entry->class_hash = class_hash;
|
|
entry->method_hash = method_hash;
|
|
entry->method = method;
|
|
}
|
|
|
|
void rava_methodcache_clear(MethodCache_t* cache) {
|
|
if (cache) {
|
|
memset(cache->entries, 0, sizeof(cache->entries));
|
|
}
|
|
}
|