Rewrite ORMTable::unprefixFieldNames
authorThiemo Mättig <thiemo.maettig@wikimedia.de>
Mon, 13 Oct 2014 17:07:30 +0000 (19:07 +0200)
committerThiemo Mättig <thiemo.maettig@wikimedia.de>
Mon, 13 Oct 2014 17:07:30 +0000 (19:07 +0200)
This method is called a lot (~1000 times each time). It calls
the callback function ~10 times per table, resulting in ~10000
calls of strlen. Which is just not necesarry. The string length does
not change.

Change-Id: I19194f1166da465a1c9ef4b2fb9cdaef4105a6f7

includes/db/ORMTable.php

index 2f898b7..ac27ee2 100644 (file)
@@ -783,7 +783,11 @@ class ORMTable extends DBAccessBase implements IORMTable {
         * @return array
         */
        public function unprefixFieldNames( array $fieldNames ) {
-               return array_map( array( $this, 'unprefixFieldName' ), $fieldNames );
+               $start = strlen( $this->fieldPrefix );
+
+               return array_map( function( $fieldName ) use ( $start ) {
+                       return substr( $fieldName, $start );
+               }, $fieldNames );
        }
 
        /**