Bug 1186791 (part 2) - Replace nsBaseHashtable::EnumerateRead() calls in storage/ with iterators. r=mak.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 29 Oct 2015 16:04:42 -0700
changeset 270467 15aad0a5b3cb1695bacaf3e4ecb40339cb7a2a1c
parent 270466 582ecb12478ae567b439bb5aa01a1ac3b9551e61
child 270468 234e629e87cc1761289130f85039bba64a6ea07e
push id86
push usercbook@mozilla.com
push dateWed, 04 Nov 2015 14:00:24 +0000
reviewersmak
bugs1186791
milestone45.0a1
Bug 1186791 (part 2) - Replace nsBaseHashtable::EnumerateRead() calls in storage/ with iterators. r=mak.
storage/mozStorageConnection.cpp
--- a/storage/mozStorageConnection.cpp
+++ b/storage/mozStorageConnection.cpp
@@ -189,34 +189,16 @@ Module gModules[] = {
 //// Local Functions
 
 void tracefunc (void *aClosure, const char *aStmt)
 {
   MOZ_LOG(gStorageLog, LogLevel::Debug, ("sqlite3_trace on %p for '%s'", aClosure,
                                      aStmt));
 }
 
-struct FFEArguments
-{
-    nsISupports *target;
-    bool found;
-};
-PLDHashOperator
-findFunctionEnumerator(const nsACString &aKey,
-                       Connection::FunctionInfo aData,
-                       void *aUserArg)
-{
-  FFEArguments *args = static_cast<FFEArguments *>(aUserArg);
-  if (aData.function == args->target) {
-    args->found = true;
-    return PL_DHASH_STOP;
-  }
-  return PL_DHASH_NEXT;
-}
-
 PLDHashOperator
 copyFunctionEnumerator(const nsACString &aKey,
                        Connection::FunctionInfo aData,
                        void *aUserArg)
 {
   NS_PRECONDITION(aData.type == Connection::FunctionInfo::SIMPLE ||
                   aData.type == Connection::FunctionInfo::AGGREGATE,
                   "Invalid function type!");
@@ -859,19 +841,23 @@ Connection::databaseElementExists(enum D
 
   return convertResultCode(srv);
 }
 
 bool
 Connection::findFunctionByInstance(nsISupports *aInstance)
 {
   sharedDBMutex.assertCurrentThreadOwns();
-  FFEArguments args = { aInstance, false };
-  (void)mFunctions.EnumerateRead(findFunctionEnumerator, &args);
-  return args.found;
+
+  for (auto iter = mFunctions.Iter(); !iter.Done(); iter.Next()) {
+    if (iter.UserData().function == aInstance) {
+      return true;
+    }
+  }
+  return false;
 }
 
 /* static */ int
 Connection::sProgressHelper(void *aArg)
 {
   Connection *_this = static_cast<Connection *>(aArg);
   return _this->progressHandler();
 }