[folks/wip/nielsdg/simple-query-fixes: 1/2] simple-query: Avoid useless string copies
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks/wip/nielsdg/simple-query-fixes: 1/2] simple-query: Avoid useless string copies
- Date: Sun, 8 Dec 2019 10:05:46 +0000 (UTC)
commit 4241e05fb02f236490abf14b0768e7ded0687f89
Author: Niels De Graef <nielsdegraef gmail com>
Date: Sun Dec 8 09:53:38 2019 +0100
simple-query: Avoid useless string copies
Also cleanup a manual for loop using foreach (as the bug that was the
cause is already fixed for a few years now).
folks/simple-query.vala | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
---
diff --git a/folks/simple-query.vala b/folks/simple-query.vala
index 2b3f1885..f168f97e 100644
--- a/folks/simple-query.vala
+++ b/folks/simple-query.vala
@@ -100,7 +100,7 @@ public class Folks.SimpleQuery : Folks.Query
this._query_string.tokenize_and_fold (this.query_locale, null);
debug ("Created simple query with tokens:");
- foreach (var token in this._query_tokens)
+ foreach (unowned string token in this._query_tokens)
debug ("\t%s", token);
/* Notify of the need to re-evaluate matches. */
@@ -156,9 +156,9 @@ public class Folks.SimpleQuery : Folks.Query
return 1;
/* Only check for matches in tokens not yet found to minimize our work */
- var tokens_remaining = new HashSet<string> ();
+ var tokens_remaining = new HashSet<unowned string> ();
- foreach (var t in this._query_tokens)
+ foreach (unowned string t in this._query_tokens)
tokens_remaining.add (t);
/* FIXME: In the future, we should find a way to know this Individual’s
@@ -173,7 +173,7 @@ public class Folks.SimpleQuery : Folks.Query
* Track the match score as we go. */
uint match_score = 0;
- foreach (var prop_name in this.match_fields)
+ foreach (unowned string prop_name in this.match_fields)
{
unowned ObjectClass iclass = individual.get_class ();
var prop_spec = iclass.find_property (prop_name);
@@ -187,7 +187,7 @@ public class Folks.SimpleQuery : Folks.Query
var iter = tokens_remaining.iterator ();
while (iter.next ())
{
- var token = iter.get ();
+ unowned string token = iter.get ();
var inc = this._prop_contains_token (individual,
individual_translit_locale, prop_name, prop_spec, token);
match_score += inc;
@@ -495,22 +495,16 @@ public class Folks.SimpleQuery : Folks.Query
var str_tokens =
str.tokenize_and_fold (str_translit_locale, out alternates);
- /* FIXME: We have to use for() rather than foreach() because of:
- * https://bugzilla.gnome.org/show_bug.cgi?id=743877 */
- for (var i = 0; str_tokens[i] != null; i++)
+ foreach (unowned string str_token in str_tokens)
{
- var str_token = str_tokens[i];
-
if (str_token == token)
return 3;
else if (str_token.has_prefix (token))
return 2;
}
- for (var i = 0; alternates[i] != null; i++)
+ foreach (unowned string str_token in alternates)
{
- var str_token = alternates[i];
-
if (str_token == token)
return 2;
else if (str_token.has_prefix (token))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]