Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/165003

Change subject: Drop ORMTable::getFieldPrefix
......................................................................

Drop ORMTable::getFieldPrefix

Internal calls to this method show up in my XDebug profiling as
the second most called method (after array_key_exists). Called
10000 times. Sure, it's very cheap and clearly not a bottleneck.
But just not necesarry to have a method for that. The benefit of
having a method is to have a dynamic prefix that can change
depending on other things in an object. But I think this is not
a good idea for a prefix.

Change-Id: I46a0d7e072d0a69e9aef5f77e92044b62e3d0ce7
---
M includes/db/ORMTable.php
M tests/phpunit/includes/db/ORMTableTest.php
M tests/phpunit/includes/db/TestORMRowTest.php
3 files changed, 6 insertions(+), 33 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/03/165003/1

diff --git a/includes/db/ORMTable.php b/includes/db/ORMTable.php
index 24fa68c..7af069c 100644
--- a/includes/db/ORMTable.php
+++ b/includes/db/ORMTable.php
@@ -126,17 +126,6 @@
        }
 
        /**
-        * Gets the db field prefix.
-        *
-        * @since 1.20
-        *
-        * @return string
-        */
-       protected function getFieldPrefix() {
-               return $this->fieldPrefix;
-       }
-
-       /**
         * @see IORMTable::getRowClass
         *
         * @since 1.21
@@ -770,7 +759,7 @@
         * @return string
         */
        public function getPrefixedField( $field ) {
-               return $this->getFieldPrefix() . $field;
+               return $this->fieldPrefix . $field;
        }
 
        /**
@@ -796,7 +785,7 @@
         * @return string
         */
        public function unprefixFieldName( $fieldName ) {
-               return substr( $fieldName, strlen( $this->getFieldPrefix() ) );
+               return substr( $fieldName, strlen( $this->fieldPrefix ) );
        }
 
        /**
diff --git a/tests/phpunit/includes/db/ORMTableTest.php 
b/tests/phpunit/includes/db/ORMTableTest.php
index 7171ee5..41e56d2 100644
--- a/tests/phpunit/includes/db/ORMTableTest.php
+++ b/tests/phpunit/includes/db/ORMTableTest.php
@@ -99,6 +99,8 @@
 
 class PageORMTableForTesting extends ORMTable {
 
+       protected $fieldPrefix = 'page_';
+
        /**
         * @see ORMTable::getName
         *
@@ -137,14 +139,5 @@
                        'namespace' => 'int',
                        'title' => 'str',
                );
-       }
-
-       /**
-        * @see ORMTable::getFieldPrefix
-        *
-        * @return string
-        */
-       protected function getFieldPrefix() {
-               return 'page_';
        }
 }
diff --git a/tests/phpunit/includes/db/TestORMRowTest.php 
b/tests/phpunit/includes/db/TestORMRowTest.php
index c9459c9..36ee8f3 100644
--- a/tests/phpunit/includes/db/TestORMRowTest.php
+++ b/tests/phpunit/includes/db/TestORMRowTest.php
@@ -150,6 +150,8 @@
 
 class TestORMTable extends ORMTable {
 
+       protected $fieldPrefix = 'test_';
+
        /**
         * Returns the name of the database table objects of this type are 
stored in.
         *
@@ -203,16 +205,5 @@
                        'moarstuff' => 'blob',
                        'time' => 'str', // TS_MW
                );
-       }
-
-       /**
-        * Gets the db field prefix.
-        *
-        * @since 1.20
-        *
-        * @return string
-        */
-       protected function getFieldPrefix() {
-               return 'test_';
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/165003
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I46a0d7e072d0a69e9aef5f77e92044b62e3d0ce7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to