added a seperate chache lookup, as encode() requires arguments expensive to build
This commit is contained in:
@@ -110,6 +110,28 @@ static bool equals(void *key1, void *key2)
|
||||
return key1 == key2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of key_encoding_t.get_cache
|
||||
*/
|
||||
static bool get_cache(private_key_encoding_t *this, key_encoding_type_t type,
|
||||
void *cache, chunk_t *encoding)
|
||||
{
|
||||
chunk_t *chunk;
|
||||
|
||||
if (type >= KEY_ENCODING_MAX || type < 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
this->lock->read_lock(this->lock);
|
||||
chunk = this->cache[type]->get(this->cache[type], cache);
|
||||
if (chunk)
|
||||
{
|
||||
*encoding = *chunk;
|
||||
}
|
||||
this->lock->unlock(this->lock);
|
||||
return !!chunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of key_encoding_t.encode
|
||||
*/
|
||||
@@ -239,6 +261,7 @@ key_encoding_t *key_encoding_create()
|
||||
key_encoding_type_t type;
|
||||
|
||||
this->public.encode = (bool(*)(key_encoding_t*, key_encoding_type_t type, void *cache, chunk_t *encoding, ...))encode;
|
||||
this->public.get_cache = (bool(*)(key_encoding_t*, key_encoding_type_t type, void *cache, chunk_t *encoding))get_cache;
|
||||
this->public.clear_cache = (void(*)(key_encoding_t*, void *cache))clear_cache;
|
||||
this->public.add_encoder = (void(*)(key_encoding_t*, key_encoder_t encoder))add_encoder;
|
||||
this->public.remove_encoder = (void(*)(key_encoding_t*, key_encoder_t encoder))remove_encoder;
|
||||
|
||||
@@ -136,6 +136,17 @@ struct key_encoding_t {
|
||||
*/
|
||||
void (*clear_cache)(key_encoding_t *this, void *cache);
|
||||
|
||||
/**
|
||||
* Check for a cached encoding.
|
||||
*
|
||||
* @param type format of the key encoding
|
||||
* @param cache key to use for caching, as given to encode()
|
||||
* @encoding encoding result, internal data
|
||||
* @return TRUE if cache entry found
|
||||
*/
|
||||
bool (*get_cache)(key_encoding_t *this, key_encoding_type_t type,
|
||||
void *cache, chunk_t *encoding);
|
||||
|
||||
/**
|
||||
* Register a key encoder function.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user