Bug 1186808 - Replace nsBaseHashtable::EnumerateRead() calls in dom/camera/ with iterators. r=mikeh.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 22 Nov 2015 14:39:01 -0800
changeset 308753 58c11f8db0b1e70cdc941c79ddf216e6436a8afe
parent 308752 52fd8e1b08444a012f41294dde33527459ab0ec3
child 308754 b181b44bfeeba4e1115d8eedebbfe267226d9b65
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikeh
bugs1186808
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1186808 - Replace nsBaseHashtable::EnumerateRead() calls in dom/camera/ with iterators. r=mikeh.
dom/camera/GonkCameraControl.cpp
dom/camera/GonkCameraControl.h
dom/camera/GonkCameraParameters.cpp
dom/camera/GonkCameraParameters.h
dom/camera/GonkRecorderProfiles.cpp
dom/camera/GonkRecorderProfiles.h
--- a/dom/camera/GonkCameraControl.cpp
+++ b/dom/camera/GonkCameraControl.cpp
@@ -2208,37 +2208,28 @@ nsGonkCameraControl::LoadRecorderProfile
       name.AssignASCII("default");
       mRecorderProfiles.Put(name, profiles[bestIndexMatch]);
     }
   }
 
   return NS_OK;
 }
 
-/* static */ PLDHashOperator
-nsGonkCameraControl::Enumerate(const nsAString& aProfileName,
-                               RecorderProfile* aProfile,
-                               void* aUserArg)
-{
-  nsTArray<nsString>* profiles = static_cast<nsTArray<nsString>*>(aUserArg);
-  MOZ_ASSERT(profiles);
-  profiles->AppendElement(aProfileName);
-  return PL_DHASH_NEXT;
-}
-
 nsresult
 nsGonkCameraControl::GetRecorderProfiles(nsTArray<nsString>& aProfiles)
 {
   nsresult rv = LoadRecorderProfiles();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   aProfiles.Clear();
-  mRecorderProfiles.EnumerateRead(Enumerate, static_cast<void*>(&aProfiles));
+  for (auto iter = mRecorderProfiles.Iter(); !iter.Done(); iter.Next()) {
+    aProfiles.AppendElement(iter.Key());
+  }
   return NS_OK;
 }
 
 ICameraControl::RecorderProfile*
 nsGonkCameraControl::GetProfileInfo(const nsAString& aProfile)
 {
   RecorderProfile* profile;
   if (!mRecorderProfiles.Get(aProfile, &profile)) {
--- a/dom/camera/GonkCameraControl.h
+++ b/dom/camera/GonkCameraControl.h
@@ -151,19 +151,16 @@ protected:
                                        const Size& aMaxSize, uint32_t aCaptureSizeKey);
   nsresult MaybeAdjustVideoSize();
   nsresult PausePreview();
   nsresult GetSupportedSize(const Size& aSize, const nsTArray<Size>& supportedSizes, Size& best);
 
   void CreatePoster(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight, int32_t aRotation);
 
   nsresult LoadRecorderProfiles();
-  static PLDHashOperator Enumerate(const nsAString& aProfileName,
-                                   RecorderProfile* aProfile,
-                                   void* aUserArg);
 
   friend class SetPictureSize;
   friend class SetThumbnailSize;
   nsresult SetPictureSize(const Size& aSize);
   nsresult SetPictureSizeImpl(const Size& aSize);
   nsresult SetThumbnailSize(const Size& aSize);
   nsresult UpdateThumbnailSize();
   nsresult SetThumbnailSizeImpl(const Size& aSize);
--- a/dom/camera/GonkCameraParameters.cpp
+++ b/dom/camera/GonkCameraParameters.cpp
@@ -64,37 +64,29 @@ GonkCameraParameters::FindVendorSpecific
       // which indicates that this key exists.
       return aPotentialKeys[i];
     }
   }
 
   return nullptr;
 }
 
-/* static */ PLDHashOperator
-GonkCameraParameters::EnumerateFlatten(const nsACString& aKey,
-                                       nsCString* aValue,
-                                       void* aUserArg)
-{
-  nsCString* data = static_cast<nsCString*>(aUserArg);
-  if (!data->IsEmpty()) {
-    data->Append(';');
-  }
-  data->Append(aKey);
-  data->Append('=');
-  data->Append(*aValue);
-  return PL_DHASH_NEXT;
-}
-
 String8
 GonkCameraParameters::Flatten() const
 {
   MutexAutoLock lock(mLock);
   nsCString data;
-  mParams.EnumerateRead(EnumerateFlatten, static_cast<void*>(&data));
+  for (auto iter = mParams.ConstIter(); !iter.Done(); iter.Next()) {
+    if (!data.IsEmpty()) {
+      data.Append(';');
+    }
+    data.Append(iter.Key());
+    data.Append('=');
+    data.Append(*iter.UserData());
+  }
   return String8(data.Data());
 }
 
 nsresult
 GonkCameraParameters::Unflatten(const String8& aFlatParameters)
 {
   MutexAutoLock lock(mLock);
   mParams.Clear();
--- a/dom/camera/GonkCameraParameters.h
+++ b/dom/camera/GonkCameraParameters.h
@@ -88,18 +88,16 @@ protected:
   const char* mVendorSpecificKeySupportedIsoModes;
   nsTArray<int> mZoomRatios;
   nsTArray<nsString> mIsoModes;
   nsTArray<nsString> mSceneModes;
   nsTArray<nsString> mMeteringModes;
   nsClassHashtable<nsStringHashKey, nsCString> mIsoModeMap;
   nsClassHashtable<nsCStringHashKey, nsCString> mParams;
 
-  static PLDHashOperator EnumerateFlatten(const nsACString& aKey, nsCString* aValue, void* aUserArg);
-
   nsresult SetImpl(const char* aKey, const char* aValue)
   {
     if (!aValue || strchr(aValue, ';') || strchr(aValue, '=')) {
       return NS_ERROR_ILLEGAL_VALUE;
     }
     nsDependentCString key(aKey);
     mParams.Put(key, new nsCString(aValue));
     return NS_OK;
--- a/dom/camera/GonkRecorderProfiles.cpp
+++ b/dom/camera/GonkRecorderProfiles.cpp
@@ -264,28 +264,16 @@ GonkRecorderProfile::GonkRecorderProfile
 {
   mOutputFormat = static_cast<output_format>(GetProfileParameter("file.format"));
   bool isValid = Translate(mOutputFormat, mContainer);
   isValid = GetMimeType(mOutputFormat, mMimeType) ? isValid : false;
 
   mIsValid = isValid && mAudio.IsValid() && mVideo.IsValid();
 }
 
-/* static */ PLDHashOperator
-GonkRecorderProfile::Enumerate(const nsAString& aProfileName,
-                               GonkRecorderProfile* aProfile,
-                               void* aUserArg)
-{
-  nsTArray<RefPtr<ICameraControl::RecorderProfile>>* profiles =
-    static_cast<nsTArray<RefPtr<ICameraControl::RecorderProfile>>*>(aUserArg);
-  MOZ_ASSERT(profiles);
-  profiles->AppendElement(aProfile);
-  return PL_DHASH_NEXT;
-}
-
 /* static */
 already_AddRefed<GonkRecorderProfile>
 GonkRecorderProfile::CreateProfile(uint32_t aCameraId, int aQuality)
 {
   if (!IsProfileSupported(aCameraId, aQuality)) {
     DOM_CAMERA_LOGI("Profile %d not supported by platform\n", aQuality);
     return nullptr;
   }
@@ -374,17 +362,19 @@ GonkRecorderProfile::GetAll(uint32_t aCa
                             nsTArray<RefPtr<ICameraControl::RecorderProfile>>& aProfiles)
 {
   ProfileHashtable* profiles = GetProfileHashtable(aCameraId);
   if (!profiles) {
     return NS_ERROR_FAILURE;
   }
 
   aProfiles.Clear();
-  profiles->EnumerateRead(Enumerate, static_cast<void*>(&aProfiles));
+  for (auto iter = profiles->Iter(); !iter.Done(); iter.Next()) {
+    aProfiles.AppendElement(iter.UserData());
+  }
 
   return NS_OK;
 }
 
 #ifdef MOZ_WIDGET_GONK
 nsresult
 GonkRecorderProfile::ConfigureRecorder(GonkRecorder& aRecorder)
 {
--- a/dom/camera/GonkRecorderProfiles.h
+++ b/dom/camera/GonkRecorderProfiles.h
@@ -137,19 +137,16 @@ protected:
   bool IsValid() const { return mIsValid; };
 
 #ifdef MOZ_WIDGET_GONK
   nsresult ConfigureRecorder(android::GonkRecorder& aRecorder);
 #endif
   static already_AddRefed<GonkRecorderProfile> CreateProfile(uint32_t aCameraId,
                                                              int aQuality);
   static ProfileHashtable* GetProfileHashtable(uint32_t aCameraId);
-  static PLDHashOperator Enumerate(const nsAString& aProfileName,
-                                   GonkRecorderProfile* aProfile,
-                                   void* aUserArg);
 
   uint32_t mCameraId;
   int mQuality;
   bool mIsValid;
   android::output_format mOutputFormat;
 
   static nsClassHashtable<nsUint32HashKey, ProfileHashtable> sProfiles;