← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1775: [core] Optimize array_group() by avoiding to_string()

 

------------------------------------------------------------
revno: 1775
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Fri 2010-03-26 22:36:00 +0100
message:
  [core] Optimize array_group() by avoiding to_string()
  
  Simple (string) casting is enough.
modified:
  core/array.lib.php


--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws

Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription.
=== modified file 'core/array.lib.php'
--- core/array.lib.php	2010-03-06 13:56:49 +0000
+++ core/array.lib.php	2010-03-26 21:36:00 +0000
@@ -721,7 +721,12 @@
 		assert('is_array($arr); // only arrays can be grouped');
 		assert('array_key_exists($key, $arr); // key must be set in all arrays');
 
-		$value = to_string($arr[$key]);
+		$value = $arr[$key];
+		if (!is_string($value) || !is_int($value))
+		{
+			/* Try to convert to string, e.g. for AnewtDateTimeAtom instances */
+			$value = (string) $value;
+		}
 
 		if (!array_key_exists($value, $groups))
 			$groups[$value] = array();