]> git.lyx.org Git - features.git/commitdiff
Use swap in InsetText::updateBuffer for notes ad friends
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 21 Jul 2018 21:58:47 +0000 (23:58 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 22 Jul 2018 10:35:05 +0000 (12:35 +0200)
Avoid as much as possible to do full copies of all counters, since
that can be exensive. Unfortunately, it is just posible when we want
to restore the saved counters.

Explanations why we use friend swap is here:
https://stackoverflow.com/questions/5695548/public-friend-swap-member-function

Part of bug #5973.

src/Counters.cpp
src/Counters.h
src/insets/InsetText.cpp

index 2daac53224dca0a4f26e6850d3b7d7a228e6c1be..3bb4d07758bbaf61828297c33388da950516b40f 100644 (file)
@@ -697,4 +697,12 @@ void Counters::endEnvironment()
 }
 
 
+void swap(Counters & c1, Counters & c2)
+{
+       Counters tmp = move(c1);
+       c1 = move(c2);
+       c2 = move(tmp);
+}
+
+
 } // namespace lyx
index 536dcc17a6a9321b3226e747dbae9c77aed57ac7..f8bb0fa6aa3d9ab9ddf232f9f3f87944654e0731 100644 (file)
@@ -239,6 +239,9 @@ private:
        std::vector<docstring> counter_stack_;
        /// Same, but for last layout.
        std::vector<Layout const *> layout_stack_;
+
+       ///
+       friend void swap(Counters &, Counters &);
 };
 
 } // namespace lyx
index 74f60e422e704349db76eeb230fd76ef726df325..d00935784dda69fa961d0328502530abe96d48e5 100644 (file)
@@ -814,13 +814,13 @@ void InsetText::updateBuffer(ParIterator const & it, UpdateType utype)
                // Note that we do not need to call:
                //      tclass.counters().clearLastLayout()
                // since we are saving and restoring the existing counters, etc.
-               Counters const savecnt = tclass.counters();
+               Counters savecnt = tclass.counters();
                tclass.counters().reset();
                // we need float information even in note insets (#9760)
                tclass.counters().current_float(savecnt.current_float());
                tclass.counters().isSubfloat(savecnt.isSubfloat());
                buffer().updateBuffer(it2, utype);
-               tclass.counters() = savecnt;
+               swap(tclass.counters(), savecnt);
        }
 }