Use DeeIndex instead of strcmp in PlaceEntryHome
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Unity |
Fix Released
|
Medium
|
Neil J. Patel | ||
unity (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
I was just skimming through the dash-fixes diff and one thing caught my
eye. As far as I can understand you merge all the results from the
global place models into _results_model right?
If that is true then this function looks pretty expensive to me:
void
PlaceEntryHome:
PlaceEntryHome *self)
{
DeeModelIter *iter, *end;
const char *uri;
uri = dee_model_
iter = dee_model_
end = dee_model_
while (iter != end)
{
if (g_strcmp0 (dee_model_
RESULT_URI), uri) == 0)
{
dee_
break;
}
iter = dee_model_next (self->
}
}
You can avoid the iterations and g_strcmp()s completely by using
DeeIndex. So create an index on the RESULT_URI column with something
ala:
In the PlaceEntryHome constructor create the index (storing the index in
a member, not a local though):
DeeAnalyzer *analyzer = dee_analyzer_
DeeIndex *uri_index = dee_hash_index_new (_results_model, analyzer);
g_free (analyzer);
And in PlaceEntryHome:
uri = dee_model_
DeeResultSet *rows = dee_index_lookup (results_index,
while (dee_result_
{
DeeModelIter* row = dee_result_set_next (rows);
dee_
}
This should make removals O(1) assuming that there is a 1:1
correspondence between URIs and rows in the model. Which there roughly
is in practice.
Cheers,
Mikkel
Changed in unity (Ubuntu): | |
status: | New → Triaged |
I don't use this method, however I took this slowness into account when redesigning the internal Places API in Unity and the lookups are much, much faster now in global search.