Bug 1367062 - Change std::map to std::unordered_map in APZCTreeManager
changed gfx/layers/FrameMetrics.h by adding a ScrollableLayerGuidHash class that will be used as the hashing function for std::unordered_maps which use ScrollableLayerGuid as keys.
changed gfx/layers/apz/src/APZCTreeManager.cpp by changing mApzcMap to a std::unordered_map.
changed gfx/layers/apz/src/APZCTreeManager.h by changing mZoomConstraints to a std::unordered_map.
MozReview-Commit-ID: JmoQzh1MvKK
--- a/gfx/layers/FrameMetrics.h
+++ b/gfx/layers/FrameMetrics.h
@@ -1099,14 +1099,23 @@ struct ZoomConstraints {
}
bool operator!=(const ZoomConstraints& other) const
{
return !(*this == other);
}
};
+struct ScrollableLayerGuidHash
+{
+ std::size_t operator()(const ScrollableLayerGuid& Guid) const
+ {
+ return Guid.Hash();
+ }
+};
+
+
typedef Maybe<ZoomConstraints> MaybeZoomConstraints;
} // namespace layers
} // namespace mozilla
#endif /* GFX_FRAMEMETRICS_H */
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -81,17 +81,17 @@ struct APZCTreeManager::TreeBuildingStat
// A list of nodes that need to be destroyed at the end of the tree building.
// This is initialized with all nodes in the old tree, and nodes are removed
// from it as we reuse them in the new tree.
nsTArray<RefPtr<HitTestingTreeNode>> mNodesToDestroy;
// This map is populated as we place APZCs into the new tree. Its purpose is
// to facilitate re-using the same APZC for different layers that scroll
// together (and thus have the same ScrollableLayerGuid).
- std::map<ScrollableLayerGuid, AsyncPanZoomController*> mApzcMap;
+ std::unordered_map<ScrollableLayerGuid, AsyncPanZoomController*, ScrollableLayerGuidHash> mApzcMap;
};
class APZCTreeManager::CheckerboardFlushObserver : public nsIObserver {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
explicit CheckerboardFlushObserver(APZCTreeManager* aTreeManager)
@@ -533,16 +533,18 @@ GetEventRegions(const ScrollNode& aLayer
nsIntRegion hitRegion(compositionBounds.ToUnknownRect());
EventRegions eventRegions(hitRegion);
eventRegions.mDispatchToContentHitRegion = eventRegions.mHitRegion;
return eventRegions;
}
return aLayer.GetEventRegions();
}
+
+
already_AddRefed<HitTestingTreeNode>
APZCTreeManager::RecycleOrCreateNode(TreeBuildingState& aState,
AsyncPanZoomController* aApzc,
uint64_t aLayersId)
{
// Find a node without an APZC and return it. Note that unless the layer tree
// actually changes, this loop should generally do an early-return on the
// first iteration, so it should be cheap in the common case.
--- a/gfx/layers/apz/src/APZCTreeManager.h
+++ b/gfx/layers/apz/src/APZCTreeManager.h
@@ -1,17 +1,17 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_layers_APZCTreeManager_h
#define mozilla_layers_APZCTreeManager_h
-#include <map> // for std::map
+#include <unordered_map> // for std::unordered_map
#include "gfxPoint.h" // for gfxPoint
#include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2
#include "mozilla/gfx/Logging.h" // for gfx::TreeLog
#include "mozilla/gfx/Matrix.h" // for Matrix4x4
#include "mozilla/layers/TouchCounter.h"// for TouchCounter
#include "mozilla/layers/IAPZCTreeManager.h" // for IAPZCTreeManager
#include "mozilla/Mutex.h" // for Mutex
@@ -36,16 +36,17 @@ namespace layers {
class Layer;
class AsyncPanZoomController;
class APZCTreeManagerParent;
class CompositorBridgeParent;
class OverscrollHandoffChain;
struct OverscrollHandoffState;
struct FlingHandoffState;
+struct ScrollableLayerGuidHash;
class LayerMetricsWrapper;
class InputQueue;
class GeckoContentController;
class HitTestingTreeNode;
class WebRenderScrollData;
/**
* ****************** NOTE ON LOCK ORDERING IN APZ **************************
@@ -541,17 +542,17 @@ private:
* lock also needs to be held when accessing the mRootNode instance variable, as that
* is considered part of the APZC tree management state.
* Finally, the lock needs to be held when accessing mZoomConstraints.
* IMPORTANT: See the note about lock ordering at the top of this file. */
mutable mozilla::Mutex mTreeLock;
RefPtr<HitTestingTreeNode> mRootNode;
/* Holds the zoom constraints for scrollable layers, as determined by the
* the main-thread gecko code. */
- std::map<ScrollableLayerGuid, ZoomConstraints> mZoomConstraints;
+ std::unordered_map<ScrollableLayerGuid, ZoomConstraints, ScrollableLayerGuidHash> mZoomConstraints;
/* This tracks the APZC that should receive all inputs for the current input event block.
* This allows touch points to move outside the thing they started on, but still have the
* touch events delivered to the same initial APZC. This will only ever be touched on the
* input delivery thread, and so does not require locking.
*/
RefPtr<AsyncPanZoomController> mApzcForInputBlock;
/* The hit result for the current input event block; this should always be in
* sync with mApzcForInputBlock.