Merge lp:~aacid/unity-scopes-shell/no_contains_before_value into lp:unity-scopes-shell

Proposed by Albert Astals Cid
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 166
Merged at revision: 171
Proposed branch: lp:~aacid/unity-scopes-shell/no_contains_before_value
Merge into: lp:unity-scopes-shell
Diff against target: 88 lines (+38/-33)
1 file modified
src/Unity/resultsmodel.cpp (+38/-33)
To merge this branch: bzr merge lp:~aacid/unity-scopes-shell/no_contains_before_value
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Paweł Stołowski (community) Approve
Review via email: mp+242750@code.launchpad.net

Commit message

Don't call Result::contains and then Result::value

Doing that means two searches in the map for every query, we can just call value()
and in the exceptional case it throws catch the exception and return QVariant()

To post a comment you must log in.
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks, good, +1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Unity/resultsmodel.cpp'
--- src/Unity/resultsmodel.cpp 2014-08-27 17:54:20 +0000
+++ src/Unity/resultsmodel.cpp 2014-11-25 10:04:47 +0000
@@ -112,15 +112,17 @@
112 return QVariant();112 return QVariant();
113 }113 }
114 std::string const& realFieldName = mappingIt->second;114 std::string const& realFieldName = mappingIt->second;
115 if (!result->contains(realFieldName)) {115 try {
116 return QVariant();116 scopes::Variant const& v = result->value(realFieldName);
117 }117 if (v.which() != scopes::Variant::Type::String) {
118 scopes::Variant const& v = result->value(realFieldName);118 return QVariant();
119 if (v.which() != scopes::Variant::Type::String) {119 }
120 return QVariant();120 return QString::fromStdString(v.get_string());
121 }121 } catch (...) {
122122 // value() throws if realFieldName is empty or the result
123 return QString::fromStdString(v.get_string());123 // doesn't have a value for it
124 return QVariant();
125 }
124}126}
125127
126QVariant128QVariant
@@ -130,30 +132,33 @@
130 if (mappingIt == m_componentMapping.end()) {132 if (mappingIt == m_componentMapping.end()) {
131 return QVariant();133 return QVariant();
132 }134 }
133 std::string const& realFieldName = mappingIt->second;135 try {
134 if (!result->contains(realFieldName)) {136 std::string const& realFieldName = mappingIt->second;
135 return QVariant();137 scopes::Variant const& v = result->value(realFieldName);
136 }138 if (v.which() != scopes::Variant::Type::Array) {
137 scopes::Variant const& v = result->value(realFieldName);139 return QVariant();
138 if (v.which() != scopes::Variant::Type::Array) {140 }
139 return QVariant();141
140 }142 QVariantList attributes;
141143 scopes::VariantArray arr(v.get_array());
142 QVariantList attributes;144 for (unsigned i = 0; i < arr.size(); i++) {
143 scopes::VariantArray arr(v.get_array());145 if (arr[i].which() != scopes::Variant::Type::Dict) {
144 for (unsigned i = 0; i < arr.size(); i++) {146 continue;
145 if (arr[i].which() != scopes::Variant::Type::Dict) {147 }
146 continue;148 QVariantMap attribute(scopeVariantToQVariant(arr[i]).toMap());
147 }149 attributes << QVariant(attribute);
148 QVariantMap attribute(scopeVariantToQVariant(arr[i]).toMap());150 // we'll limit the number of attributes
149 attributes << QVariant(attribute);151 if (attributes.size() >= m_maxAttributes) {
150 // we'll limit the number of attributes152 break;
151 if (attributes.size() >= m_maxAttributes) {153 }
152 break;154 }
153 }155
154 }156 return attributes;
155157 } catch (...) {
156 return attributes;158 // value() throws if realFieldName is empty or the result
159 // doesn't have a value for it
160 return QVariant();
161 }
157}162}
158163
159QHash<int, QByteArray> ResultsModel::roleNames() const164QHash<int, QByteArray> ResultsModel::roleNames() const

Subscribers

People subscribed via source and target branches

to all changes: