[folks/wip/nielsdg/performance: 4/5] edsf: Avoid E.VCardAttribute.get_value()




commit 25d83d3e06851222b920245081d8b238b37aec73
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Oct 4 16:50:23 2020 +0200

    edsf: Avoid E.VCardAttribute.get_value()
    
    This will always copy the value, even when we don't need it. Use
    `get_values()` instead, and return the first element.

 backends/eds/lib/edsf-persona-store.vala |  4 +++-
 backends/eds/lib/edsf-persona.vala       | 24 +++++++++++++++---------
 2 files changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index be2fb15a..2eb99e67 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -1721,7 +1721,9 @@ public class Edsf.PersonaStore : Folks.PersonaStore
           return null;
         }
 
-      var details = new ExtendedFieldDetails (attr.get_value (), null);
+      unowned var vals = attr.get_values ();
+      unowned string? val = (vals != null)? vals.data : null;
+      var details = new ExtendedFieldDetails (val, null);
 
       foreach (unowned E.VCardAttributeParam param in attr.get_params ())
         {
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index f763a1bd..5f03d248 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -1181,7 +1181,7 @@ public class Edsf.Persona : Folks.Persona,
 
       if (gender_attr != null)
         {
-          var val = ((!) gender_attr).get_value ();
+          unowned var val = get_vcard_attr_value ((!) gender_attr);
           if (val != null)
             {
               switch (((!) val).up ())
@@ -1278,7 +1278,7 @@ public class Edsf.Persona : Folks.Persona,
           if (attr.get_name () != "X-ROLES")
             continue;
 
-          var val = attr.get_value ();
+          unowned var val = get_vcard_attr_value (attr);
           if (val == null || (!) val == "")
              {
               continue;
@@ -1426,7 +1426,7 @@ public class Edsf.Persona : Folks.Persona,
       var attrs = this.contact.get_attributes (E.ContactField.EMAIL);
       foreach (unowned E.VCardAttribute attr in attrs)
         {
-          var val = attr.get_value ();
+          unowned var val = get_vcard_attr_value (attr);
           if (val == null || (!) val == "")
             {
               continue;
@@ -1648,7 +1648,7 @@ public class Edsf.Persona : Folks.Persona,
         {
           if (attr.get_name () == "X-URIS")
             {
-              var val = attr.get_value ();
+              unowned var val = get_vcard_attr_value (attr);
               if (val == null || (!) val == "")
                 {
                   continue;
@@ -1686,7 +1686,7 @@ public class Edsf.Persona : Folks.Persona,
             {
               try
                 {
-                  var addr = attr.get_value ();
+                  unowned var addr = get_vcard_attr_value (attr);
                   if (addr == null || (!) addr == "")
                     {
                       continue;
@@ -1998,7 +1998,7 @@ public class Edsf.Persona : Folks.Persona,
       var attrs = this.contact.get_attributes (E.ContactField.TEL);
       foreach (unowned E.VCardAttribute attr in attrs)
         {
-          var val = attr.get_value ();
+          unowned var val = get_vcard_attr_value (attr);
           if (val == null || (!) val == "")
             {
               continue;
@@ -2207,7 +2207,7 @@ public class Edsf.Persona : Folks.Persona,
           this.contact.get_attribute ("X-FOLKS-FAVOURITE");
       if (fav != null)
         {
-          var val = ((!) fav).get_value ();
+          unowned var val = get_vcard_attr_value ((!) fav);
           if (val != null && ((!) val).down () == "true")
             {
               is_fav = true;
@@ -2233,7 +2233,7 @@ public class Edsf.Persona : Folks.Persona,
               continue;
             }
 
-          var val = attr.get_value ();
+          unowned var val = get_vcard_attr_value (attr);
           if (val == null || (!) val == "")
              {
               continue;
@@ -2264,7 +2264,7 @@ public class Edsf.Persona : Folks.Persona,
           prop_name);
     }
 
-  // We can prevent a lot of string copies here
+  // Some helpers to prevent a lot of string copies
   private unowned string? _get_string_property (string prop_name)
     {
       var field = E.Contact.field_id (prop_name);
@@ -2272,6 +2272,12 @@ public class Edsf.Persona : Folks.Persona,
       return contact.get_const<string> (field);
     }
 
+  private unowned string? get_vcard_attr_value (E.VCardAttribute attr)
+    {
+      unowned var values = attr.get_values ();
+      return (values != null)? values.data : null;
+    }
+
   private unowned string? _im_proto_from_addr (string addr)
     {
       if (addr.index_of ("@") == -1)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]