summaryrefslogtreecommitdiff
path: root/include/mbgl/util
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-05-31 13:53:48 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-06-05 19:38:08 -0700
commit9dfc2d924d440560adb2db13c758b2c5b3b7dd47 (patch)
tree8d1868b5b011676fd0a7d260e0c3560cd36db6b9 /include/mbgl/util
parent97eb62fe7cc10fd882f6e361c461900687361460 (diff)
downloadqtlocation-mapboxgl-9dfc2d924d440560adb2db13c758b2c5b3b7dd47.tar.gz
[core] Collection-level immutability
Introduce a second level of immutability, over each of the collections held by a style: sources, images, and layers. Tracking immutability at this level allows us to short-circuit significant portions of the RenderStyle update logic via a simple equality check, greatly improving performance.
Diffstat (limited to 'include/mbgl/util')
-rw-r--r--include/mbgl/util/immutable.hpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/mbgl/util/immutable.hpp b/include/mbgl/util/immutable.hpp
index 2cdce8772d..eb26c0d282 100644
--- a/include/mbgl/util/immutable.hpp
+++ b/include/mbgl/util/immutable.hpp
@@ -115,4 +115,19 @@ Immutable<S> staticImmutableCast(const Immutable<U>& u) {
return Immutable<S>(std::static_pointer_cast<const S>(u.ptr));
}
+/**
+ * Constrained mutation of an immutable reference. Makes a temporarily-mutable copy of the
+ * input Immutable using the inner type's copy constructor, runs the given callable on the
+ * mutable copy, and then freezes the copy and reassigns it to the input reference.
+ *
+ * Note that other Immutables referring to the same inner instance are not affected; they
+ * continue to referencing the original immutable instance.
+ */
+template <class T, class Fn>
+void mutate(Immutable<T>& immutable, Fn&& fn) {
+ Mutable<T> mut = makeMutable<T>(*immutable);
+ std::forward<Fn>(fn)(*mut);
+ immutable = std::move(mut);
+}
+
} // namespace mbgl