diff options
author | lloyd <[email protected]> | 2008-11-11 18:03:44 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-11 18:03:44 +0000 |
commit | 6a1e19928007c0047518e8e15b92bba116bf7a58 (patch) | |
tree | 70ce4ccb0f859884dac49895ebcff3e1d00b6b2e /src/algo_factory/algo_factory.cpp | |
parent | a26685bf9feee9b9457bd1313b3943701aa37367 (diff) |
Add a new cache at the level of Algorithm_Factory. Intent is to replace
the caches included in the Engines, allowing faster search/query along
and making the Engine implementations mostly or entirely stateless, also
removing the need for a two-phase initialization there.
Stil buggy + incomplete.
Diffstat (limited to 'src/algo_factory/algo_factory.cpp')
-rw-r--r-- | src/algo_factory/algo_factory.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/algo_factory/algo_factory.cpp b/src/algo_factory/algo_factory.cpp index b8c428432..1f49a0d48 100644 --- a/src/algo_factory/algo_factory.cpp +++ b/src/algo_factory/algo_factory.cpp @@ -17,6 +17,13 @@ Algorithm Factory namespace Botan { +Algorithm_Factory::Algorithm_Factory(Mutex_Factory& mf) : + mutex_factory(mf), + hash_cache(mf.make()) + { + + } + /** * Delete all engines */ @@ -176,6 +183,7 @@ void Algorithm_Factory::add_stream_cipher(StreamCipher* hash) const HashFunction* Algorithm_Factory::prototype_hash_function(const SCAN_Name& request) { +#if 1 for(u32bit i = 0; i != engines.size(); ++i) { if(request.provider_allowed(engines[i]->provider_name())) @@ -189,6 +197,28 @@ Algorithm_Factory::prototype_hash_function(const SCAN_Name& request) } return 0; +#else + const HashFunction* cache_hit = hash_cache.get(request); + if(cache_hit) + return cache_hit; + + // Search for all providers of this algorithm and add them to the cache + for(u32bit i = 0; i != engines.size(); ++i) + { + const std::string provider = engines[i]->provider_name(); + HashFunction* impl = engines[i]->find_hash(request, *this); + + if(impl) + hash_cache.add(impl, provider); + } + + /* Now try the cache search again (if the providers don't match up + with ones that exist in this build, this might still fail and + return 0). + */ + + return hash_cache.get(request); +#endif } /** |