[folks] Cut unnecessary casting.



commit 6aa04aae7ffda13afe2654a8a3e6b1d9c42c4ff3
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Tue Dec 28 16:58:34 2010 -0800

    Cut unnecessary casting.
    
    Excessive casting can hide real compiler warnings/errors and is best avoided.
    
    Helps bgo#629083

 HACKING                           |    3 +++
 backends/key-file/kf-persona.vala |    3 +--
 folks/has-presence.vala           |    5 ++---
 folks/individual-aggregator.vala  |   12 +++++-------
 4 files changed, 11 insertions(+), 12 deletions(-)
---
diff --git a/HACKING b/HACKING
index be18fdc..fdaa818 100644
--- a/HACKING
+++ b/HACKING
@@ -97,3 +97,6 @@ Vala-specific rules
    reduces readability without benefit. And, as of this writing, bgo#638199
    forces unowned variables to have an explicit type (preventing the use of
    'var').
+
+9. As in most languages, avoid casting. Casting is usually a sign of an error
+   which should be fixed and reduces readability.
diff --git a/backends/key-file/kf-persona.vala b/backends/key-file/kf-persona.vala
index cc6ecf6..c83a595 100644
--- a/backends/key-file/kf-persona.vala
+++ b/backends/key-file/kf-persona.vala
@@ -82,11 +82,10 @@ public class Folks.Backends.Kf.Persona : Folks.Persona,
       set
         {
           /* Remove the current IM addresses from the key file */
-          this._im_addresses.foreach ((k, v) =>
+          this._im_addresses.foreach ((protocol, v) =>
             {
               try
                 {
-                  unowned string protocol = (string) k;
                   this._key_file.remove_key (this.display_id, protocol);
                 }
               catch (KeyFileError e)
diff --git a/folks/has-presence.vala b/folks/has-presence.vala
index 842313f..76415df 100644
--- a/folks/has-presence.vala
+++ b/folks/has-presence.vala
@@ -101,7 +101,7 @@ public interface Folks.HasPresence : Object
 
   /* Rank the presence types for comparison purposes, with higher numbers
    * meaning more available */
-  private static uint _type_availability (PresenceType type)
+  private static int _type_availability (PresenceType type)
     {
       switch (type)
         {
@@ -142,8 +142,7 @@ public interface Folks.HasPresence : Object
    */
   public static int typecmp (PresenceType type_a, PresenceType type_b)
     {
-      return (int) _type_availability (type_a) -
-          (int) _type_availability (type_b);
+      return _type_availability (type_a) - _type_availability (type_b);
     }
 
   /**
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index 604a739..5253554 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -357,7 +357,7 @@ public class Folks.IndividualAggregator : Object
 
                   persona.linkable_property_to_links (prop_name, (l) =>
                     {
-                      unowned string prop_linking_value = (string) l;
+                      unowned string prop_linking_value = l;
                       var candidate_ind =
                           this._link_map.lookup (prop_linking_value);
 
@@ -454,7 +454,7 @@ public class Folks.IndividualAggregator : Object
                       final_persona.linkable_property_to_links (prop_name,
                           (l) =>
                         {
-                          unowned string prop_linking_value = (string) l;
+                          unowned string prop_linking_value = l;
 
                           debug ("            %s", prop_linking_value);
                           this._link_map.replace (prop_linking_value,
@@ -519,12 +519,10 @@ public class Folks.IndividualAggregator : Object
                   continue;
                 }
 
-              persona.linkable_property_to_links (prop_name, (l) =>
+              persona.linkable_property_to_links (prop_name, (linking_value) =>
                 {
-                  unowned string prop_linking_value = (string) l;
-
-                  debug ("        %s", prop_linking_value);
-                  this._link_map.remove (prop_linking_value);
+                  debug ("        %s", linking_value);
+                  this._link_map.remove (linking_value);
                 });
             }
         }



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