summaryrefslogtreecommitdiff
path: root/unity-shared
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2015-02-03 10:46:48 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2015-02-03 10:46:48 +0100
commit6a6bb14cb03f4203efa09985bdbc15270a4011ab (patch)
treee662770aa6ccf43ae74a6547c8b7393e7388e906 /unity-shared
parent35ec9452c22f81279a8489364c212f08a67ed3f9 (diff)
Unity: Use unordered_map whenever possible
As iterating over it seems just fast as in the ordered version, we just speedup lookups and insertions. (bzr r3899.2.51)
Diffstat (limited to 'unity-shared')
-rw-r--r--unity-shared/IconLoader.cpp4
-rw-r--r--unity-shared/NuxObjectPtrHash.h36
-rw-r--r--unity-shared/PluginAdapter.h2
-rw-r--r--unity-shared/PreviewStyle.cpp2
-rw-r--r--unity-shared/UBusWrapper.cpp9
-rw-r--r--unity-shared/UBusWrapper.h4
6 files changed, 47 insertions, 10 deletions
diff --git a/unity-shared/IconLoader.cpp b/unity-shared/IconLoader.cpp
index 021eb6dcf..67686f4e9 100644
--- a/unity-shared/IconLoader.cpp
+++ b/unity-shared/IconLoader.cpp
@@ -799,7 +799,7 @@ private:
bool CoalesceTasksCb();
private:
- std::map<std::string, glib::Object<GdkPixbuf>> cache_;
+ std::unordered_map<std::string, glib::Object<GdkPixbuf>> cache_;
/* FIXME: the reference counting of IconLoaderTasks with shared pointers
* is currently somewhat broken, and the queued_tasks_ member is what keeps
* it from crashing randomly.
@@ -807,7 +807,7 @@ private:
* tasks, but when they are being completed in a worker thread, the thread
* should own them as well (yet it doesn't), this could cause trouble
* in the future... You've been warned! */
- std::map<std::string, IconLoaderTask::Ptr> queued_tasks_;
+ std::unordered_map<std::string, IconLoaderTask::Ptr> queued_tasks_;
std::queue<IconLoaderTask::Ptr> tasks_;
std::unordered_map<Handle, IconLoaderTask::Ptr> task_map_;
std::vector<IconLoaderTask*> finished_tasks_;
diff --git a/unity-shared/NuxObjectPtrHash.h b/unity-shared/NuxObjectPtrHash.h
new file mode 100644
index 000000000..141957c35
--- /dev/null
+++ b/unity-shared/NuxObjectPtrHash.h
@@ -0,0 +1,36 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2015 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Marco Trevisan <marco.trevisan@canonical.com>
+ */
+
+#ifndef NUX_OBJECT_PTR_HASH
+#define NUX_OBJECT_PTR_HASH
+
+#include <functional>
+namespace std
+{
+// Template specialization, needed for unordered_{map,set}
+template<typename T> struct hash<nux::ObjectPtr<T>>
+{
+ std::size_t operator()(nux::ObjectPtr<T> const& o) const
+ {
+ return std::hash<T*>()(o.GetPointer());
+ }
+};
+}
+
+#endif // NUX_OBJECT_PTR_HASH
diff --git a/unity-shared/PluginAdapter.h b/unity-shared/PluginAdapter.h
index d0a2ec7d7..1c6b4a18b 100644
--- a/unity-shared/PluginAdapter.h
+++ b/unity-shared/PluginAdapter.h
@@ -50,7 +50,7 @@ private:
CompAction* GetAction(std::string const& name) const;
CompAction* primary_action_;
- std::map<std::string, CompAction*> actions_;
+ std::unordered_map<std::string, CompAction*> actions_;
};
diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp
index f9f99e738..c165bca12 100644
--- a/unity-shared/PreviewStyle.cpp
+++ b/unity-shared/PreviewStyle.cpp
@@ -83,7 +83,7 @@ private:
}
private:
std::string filename_;
- std::map<int, BaseTexturePtr> textures_;
+ std::unordered_map<int, BaseTexturePtr> textures_;
};
} // namespace
diff --git a/unity-shared/UBusWrapper.cpp b/unity-shared/UBusWrapper.cpp
index ecdd39d68..3f1699923 100644
--- a/unity-shared/UBusWrapper.cpp
+++ b/unity-shared/UBusWrapper.cpp
@@ -32,11 +32,12 @@ UBusManager::UBusManager()
UBusManager::~UBusManager()
{
- // we don't want to modify a container while iterating it
- std::set<unsigned> ids_copy(connection_ids_);
- for (auto it = ids_copy.begin(); it != ids_copy.end(); ++it)
+ for (auto it = connection_ids_.begin(); it != connection_ids_.end();)
{
- UnregisterInterest(*it);
+ auto tmp_it = it;
+ ++it;
+ server->UnregisterInterest(*tmp_it);
+ connection_ids_.erase(tmp_it);
}
}
diff --git a/unity-shared/UBusWrapper.h b/unity-shared/UBusWrapper.h
index 764efea1c..56a111a5b 100644
--- a/unity-shared/UBusWrapper.h
+++ b/unity-shared/UBusWrapper.h
@@ -22,7 +22,7 @@
#include <memory>
#include <string>
-#include <set>
+#include <unordered_set>
#include <UnityCore/Variant.h>
#include <UnityCore/GLibSource.h>
@@ -47,7 +47,7 @@ public:
private:
static std::unique_ptr<UBusServer> server;
- std::set<unsigned> connection_ids_;
+ std::unordered_set<unsigned> connection_ids_;
};
}