Author: breser
Date: Thu Jul 25 23:36:22 2013
New Revision: 1507155

URL: http://svn.apache.org/r1507155
Log:
Fix possible duplication of work when using svn_hash_sets() macro.

svn_hash_sets() is a macro that uses the key argument twice, so the expression
used in the key argument will be evaluated twice.  We often put calls to
apr_pstrdup() and other functions in that position, which causes unnecessary
extra work and memory usage.

* subversion/include/svn_hash.h
  (svn_hash_sets): Use a variable to avoid executing key expression twice.

Modified:
    subversion/trunk/subversion/include/svn_hash.h

Modified: subversion/trunk/subversion/include/svn_hash.h
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_hash.h?rev=1507155&r1=1507154&r2=1507155&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_hash.h (original)
+++ subversion/trunk/subversion/include/svn_hash.h Thu Jul 25 23:36:22 2013
@@ -251,8 +251,11 @@ svn_hash_from_cstring_keys(apr_hash_t **
  *
  * @since New in 1.8.
  */
-#define svn_hash_sets(ht, key, val) \
-            apr_hash_set(ht, key, strlen(key), val)
+#define svn_hash_sets(ht, key, val)                 \
+  do {                                              \
+    const void *keystr = (key);                     \
+    apr_hash_set(ht, keystr, strlen(keystr), val);  \
+  } while (0)
 
 /** @} */
 


Reply via email to