[gjs] object: Pass std::function objects by reference



commit b040535a92224aa38e5626d8bf474c1ae9e0b039
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Jun 18 01:06:09 2019 +0200

    object: Pass std::function objects by reference
    
    Don't copy the actual object multiple times, as we can just use a
    const reference to it.

 gi/object.cpp | 14 ++++++--------
 gi/object.h   |  5 +++--
 2 files changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 3d0064b5..6fc925d3 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1033,9 +1033,8 @@ ObjectInstance::gobj_dispose_notify(void)
     unlink();
 }
 
-void
-ObjectInstance::iterate_wrapped_gobjects(ObjectInstance::Action action)
-{
+void ObjectInstance::iterate_wrapped_gobjects(
+    const ObjectInstance::Action& action) {
     ObjectInstance *link = ObjectInstance::wrapped_gobject_list;
     while (link) {
         ObjectInstance *next = link->next();
@@ -1044,12 +1043,11 @@ ObjectInstance::iterate_wrapped_gobjects(ObjectInstance::Action action)
     }
 }
 
-void
-ObjectInstance::remove_wrapped_gobjects_if(ObjectInstance::Predicate predicate,
-                                           ObjectInstance::Action action)
-{
+void ObjectInstance::remove_wrapped_gobjects_if(
+    const ObjectInstance::Predicate& predicate,
+    const ObjectInstance::Action& action) {
     std::vector<ObjectInstance *> removed;
-    iterate_wrapped_gobjects([&](ObjectInstance *link) {
+    iterate_wrapped_gobjects([&predicate, &removed](ObjectInstance* link) {
         if (predicate(link)) {
             removed.push_back(link);
             link->unlink();
diff --git a/gi/object.h b/gi/object.h
index c7df2039..24f89acc 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -393,8 +393,9 @@ class ObjectInstance : public GIWrapperInstance<ObjectBase, ObjectPrototype,
     }
     using Action = std::function<void(ObjectInstance*)>;
     using Predicate = std::function<bool(ObjectInstance*)>;
-    static void iterate_wrapped_gobjects(Action action);
-    static void remove_wrapped_gobjects_if(Predicate predicate, Action action);
+    static void iterate_wrapped_gobjects(const Action& action);
+    static void remove_wrapped_gobjects_if(const Predicate& predicate,
+                                           const Action& action);
 
  public:
     GJS_USE GjsListLink* get_link(void) { return &m_instance_link; }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]