From 41fdd72e06d517974fbb5b836aabb227d0482f96 Mon Sep 17 00:00:00 2001 From: scottmk Date: Wed, 22 Jul 2009 03:50:13 +0000 Subject: [PATCH] This is a performance tweak to the osrfHashGet function, a widely used utility function. The old version accepted a variable number of arguments: a pointer to an osrfHash, a string optionally containing printf-style format specifiers, and addtional parameters as needed to fill in the blanks. In practice, none of the code ever uses the printf-style formatting. We always pass exactly two parameters. We burn CPU cycles scanning the string for format specifiers and never find any. I eliminated the unused variable parameters and turned osrfHashGet() into a simple two-parameter function. Just in case anybody ever wants it, I also cloned the original version into a new function named osrfHashGetFmt, which accepts a variable number of arguments as before. Note that, since the signature of the function is changing, it is necessary to recompile any open-ils programs that call it, namely: oils_dataloader.c oils_event.c oils_idl-core.c oils_cstore.c dump_idl.c The Makefiles apparently don't recognize this dependency. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1726 9efc2488-bf62-4759-914b-345cdb29e865 --- include/opensrf/osrf_hash.h | 3 ++- src/libopensrf/osrf_hash.c | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/opensrf/osrf_hash.h b/include/opensrf/osrf_hash.h index 47b9735..2bfcbc2 100644 --- a/include/opensrf/osrf_hash.h +++ b/include/opensrf/osrf_hash.h @@ -42,8 +42,9 @@ void* osrfHashSet( osrfHash* hash, void* item, const char* key, ... ); */ void* osrfHashRemove( osrfHash* hash, const char* key, ... ); -void* osrfHashGet( osrfHash* hash, const char* key, ... ); +void* osrfHashGet( osrfHash* hash, const char* key ); +void* osrfHashGetFmt( osrfHash* hash, const char* key, ... ); /** @return A list of strings representing the keys of the hash. diff --git a/src/libopensrf/osrf_hash.c b/src/libopensrf/osrf_hash.c index 2a0a341..377d595 100644 --- a/src/libopensrf/osrf_hash.c +++ b/src/libopensrf/osrf_hash.c @@ -252,7 +252,13 @@ void* osrfHashRemove( osrfHash* hash, const char* key, ... ) { } -void* osrfHashGet( osrfHash* hash, const char* key, ... ) { +void* osrfHashGet( osrfHash* hash, const char* key ) { + osrfHashNode* node = find_item( hash, key, NULL ); + if( !node ) return NULL; + return node->item; +} + +void* osrfHashGetFmt( osrfHash* hash, const char* key, ... ) { if(!(hash && key )) return NULL; VA_LIST_TO_STRING(key); -- 2.43.2