aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Valkeinen2017-11-22 02:09:30 -0600
committerTomi Valkeinen2017-11-22 04:47:15 -0600
commit75e85e48c35f9e18a974af1c1e973d9482ed1fc4 (patch)
treeb5d30658dc4fb16ae5d82d452bfe648abcd3dab3
parenta4724a1dae7a877ae7bb7082b068bbb12032ff63 (diff)
downloadexternal-libkmsxx-75e85e48c35f9e18a974af1c1e973d9482ed1fc4.tar.gz
external-libkmsxx-75e85e48c35f9e18a974af1c1e973d9482ed1fc4.tar.xz
external-libkmsxx-75e85e48c35f9e18a974af1c1e973d9482ed1fc4.zip
resman: use set<> instead of vector<>
-rw-r--r--kms++util/inc/kms++util/resourcemanager.h8
-rw-r--r--kms++util/src/resourcemanager.cpp47
2 files changed, 24 insertions, 31 deletions
diff --git a/kms++util/inc/kms++util/resourcemanager.h b/kms++util/inc/kms++util/resourcemanager.h
index 002b4c9..1b5cf21 100644
--- a/kms++util/inc/kms++util/resourcemanager.h
+++ b/kms++util/inc/kms++util/resourcemanager.h
@@ -1,5 +1,5 @@
1#include <kms++/kms++.h> 1#include <kms++/kms++.h>
2#include <vector> 2#include <set>
3#include <string> 3#include <string>
4 4
5namespace kms { 5namespace kms {
@@ -24,9 +24,9 @@ public:
24 24
25private: 25private:
26 Card& m_card; 26 Card& m_card;
27 std::vector<Connector*> m_reserved_connectors; 27 std::set<Connector*> m_reserved_connectors;
28 std::vector<Crtc*> m_reserved_crtcs; 28 std::set<Crtc*> m_reserved_crtcs;
29 std::vector<Plane*> m_reserved_planes; 29 std::set<Plane*> m_reserved_planes;
30}; 30};
31 31
32} 32}
diff --git a/kms++util/src/resourcemanager.cpp b/kms++util/src/resourcemanager.cpp
index 465d817..9a8a66b 100644
--- a/kms++util/src/resourcemanager.cpp
+++ b/kms++util/src/resourcemanager.cpp
@@ -5,13 +5,6 @@
5using namespace kms; 5using namespace kms;
6using namespace std; 6using namespace std;
7 7
8template<class C, class T>
9auto contains(const C& v, const T& x)
10-> decltype(end(v), true)
11{
12 return end(v) != std::find(begin(v), end(v), x);
13}
14
15ResourceManager::ResourceManager(Card& card) 8ResourceManager::ResourceManager(Card& card)
16 : m_card(card) 9 : m_card(card)
17{ 10{
@@ -24,13 +17,13 @@ void ResourceManager::reset()
24 m_reserved_planes.clear(); 17 m_reserved_planes.clear();
25} 18}
26 19
27static Connector* find_connector(Card& card, const vector<Connector*> reserved) 20static Connector* find_connector(Card& card, const set<Connector*> reserved)
28{ 21{
29 for (Connector* conn : card.get_connectors()) { 22 for (Connector* conn : card.get_connectors()) {
30 if (!conn->connected()) 23 if (!conn->connected())
31 continue; 24 continue;
32 25
33 if (contains(reserved, conn)) 26 if (reserved.count(conn))
34 continue; 27 continue;
35 28
36 return conn; 29 return conn;
@@ -39,7 +32,7 @@ static Connector* find_connector(Card& card, const vector<Connector*> reserved)
39 return nullptr; 32 return nullptr;
40} 33}
41 34
42static Connector* resolve_connector(Card& card, const string& name, const vector<Connector*> reserved) 35static Connector* resolve_connector(Card& card, const string& name, const set<Connector*> reserved)
43{ 36{
44 auto connectors = card.get_connectors(); 37 auto connectors = card.get_connectors();
45 38
@@ -49,7 +42,7 @@ static Connector* resolve_connector(Card& card, const string& name, const vector
49 if (*endptr == 0) { 42 if (*endptr == 0) {
50 Connector* c = card.get_connector(id); 43 Connector* c = card.get_connector(id);
51 44
52 if (!c || contains(reserved, c)) 45 if (!c || reserved.count(c))
53 return nullptr; 46 return nullptr;
54 47
55 return c; 48 return c;
@@ -63,7 +56,7 @@ static Connector* resolve_connector(Card& card, const string& name, const vector
63 56
64 Connector* c = connectors[idx]; 57 Connector* c = connectors[idx];
65 58
66 if (contains(reserved, c)) 59 if (reserved.count(c))
67 return nullptr; 60 return nullptr;
68 61
69 return c; 62 return c;
@@ -74,7 +67,7 @@ static Connector* resolve_connector(Card& card, const string& name, const vector
74 if (to_lower(conn->fullname()).find(to_lower(name)) == string::npos) 67 if (to_lower(conn->fullname()).find(to_lower(name)) == string::npos)
75 continue; 68 continue;
76 69
77 if (contains(reserved, conn)) 70 if (reserved.count(conn))
78 continue; 71 continue;
79 72
80 return conn; 73 return conn;
@@ -95,7 +88,7 @@ Connector* ResourceManager::reserve_connector(const string& name)
95 if (!conn) 88 if (!conn)
96 return nullptr; 89 return nullptr;
97 90
98 m_reserved_connectors.push_back(conn); 91 m_reserved_connectors.insert(conn);
99 return conn; 92 return conn;
100} 93}
101 94
@@ -104,10 +97,10 @@ Connector* ResourceManager::reserve_connector(Connector* conn)
104 if (!conn) 97 if (!conn)
105 return nullptr; 98 return nullptr;
106 99
107 if (contains(m_reserved_connectors, conn)) 100 if (m_reserved_connectors.count(conn))
108 return nullptr; 101 return nullptr;
109 102
110 m_reserved_connectors.push_back(conn); 103 m_reserved_connectors.insert(conn);
111 return conn; 104 return conn;
112} 105}
113 106
@@ -117,15 +110,15 @@ Crtc* ResourceManager::reserve_crtc(Connector* conn)
117 return nullptr; 110 return nullptr;
118 111
119 if (Crtc* crtc = conn->get_current_crtc()) { 112 if (Crtc* crtc = conn->get_current_crtc()) {
120 m_reserved_crtcs.push_back(crtc); 113 m_reserved_crtcs.insert(crtc);
121 return crtc; 114 return crtc;
122 } 115 }
123 116
124 for (Crtc* crtc : conn->get_possible_crtcs()) { 117 for (Crtc* crtc : conn->get_possible_crtcs()) {
125 if (contains(m_reserved_crtcs, crtc)) 118 if (m_reserved_crtcs.count(crtc))
126 continue; 119 continue;
127 120
128 m_reserved_crtcs.push_back(crtc); 121 m_reserved_crtcs.insert(crtc);
129 return crtc; 122 return crtc;
130 } 123 }
131 124
@@ -137,10 +130,10 @@ Crtc* ResourceManager::reserve_crtc(Crtc* crtc)
137 if (!crtc) 130 if (!crtc)
138 return nullptr; 131 return nullptr;
139 132
140 if (contains(m_reserved_crtcs, crtc)) 133 if (m_reserved_crtcs.count(crtc))
141 return nullptr; 134 return nullptr;
142 135
143 m_reserved_crtcs.push_back(crtc); 136 m_reserved_crtcs.insert(crtc);
144 137
145 return crtc; 138 return crtc;
146} 139}
@@ -157,10 +150,10 @@ Plane* ResourceManager::reserve_plane(Crtc* crtc, PlaneType type, PixelFormat fo
157 if (format != PixelFormat::Undefined && !plane->supports_format(format)) 150 if (format != PixelFormat::Undefined && !plane->supports_format(format))
158 continue; 151 continue;
159 152
160 if (contains(m_reserved_planes, plane)) 153 if (m_reserved_planes.count(plane))
161 continue; 154 continue;
162 155
163 m_reserved_planes.push_back(plane); 156 m_reserved_planes.insert(plane);
164 return plane; 157 return plane;
165 } 158 }
166 159
@@ -172,10 +165,10 @@ Plane* ResourceManager::reserve_plane(Plane* plane)
172 if (!plane) 165 if (!plane)
173 return nullptr; 166 return nullptr;
174 167
175 if (contains(m_reserved_planes, plane)) 168 if (m_reserved_planes.count(plane))
176 return nullptr; 169 return nullptr;
177 170
178 m_reserved_planes.push_back(plane); 171 m_reserved_planes.insert(plane);
179 172
180 return plane; 173 return plane;
181} 174}
@@ -192,10 +185,10 @@ Plane* ResourceManager::reserve_generic_plane(Crtc* crtc, PixelFormat format)
192 if (format != PixelFormat::Undefined && !plane->supports_format(format)) 185 if (format != PixelFormat::Undefined && !plane->supports_format(format))
193 continue; 186 continue;
194 187
195 if (contains(m_reserved_planes, plane)) 188 if (m_reserved_planes.count(plane))
196 continue; 189 continue;
197 190
198 m_reserved_planes.push_back(plane); 191 m_reserved_planes.insert(plane);
199 return plane; 192 return plane;
200 } 193 }
201 194