* This is now used by SectionProfiler and avoids the high overhead of call_user_func_array().
Change-Id: I7ff2c9a35c7cd8ee462f2368b655e766ad33dd63
'SearchResultSet' => __DIR__ . '/includes/search/SearchResultSet.php',
'SearchSqlite' => __DIR__ . '/includes/search/SearchSqlite.php',
'SearchUpdate' => __DIR__ . '/includes/deferred/SearchUpdate.php',
+ 'SectionProfileCallback' => __DIR__ . '/includes/profiler/SectionProfiler.php',
'SectionProfiler' => __DIR__ . '/includes/profiler/SectionProfiler.php',
'SevenZipStream' => __DIR__ . '/maintenance/7zip.inc',
'ShiConverter' => __DIR__ . '/languages/classes/LanguageShi.php',
protected $params;
/**
- * @param callable $callback
+ * @param callable|null $callback
* @param array $params Callback arguments (since 1.25)
* @throws Exception
*/
public function __construct( $callback, array $params = array() ) {
- if ( !is_callable( $callback ) ) {
+ if ( $callback !== null && !is_callable( $callback ) ) {
throw new InvalidArgumentException( "Provided callback is not valid." );
}
$this->callback = $callback;
}
public function scopedProfileIn( $section ) {
- return new ScopedCallback( function () {
- // no-op
- } );
+ return new ScopedCallback( null ); // no-op
}
public function getFunctionStats() {
public function scopedProfileIn( $section ) {
$this->profileInInternal( $section );
- $that = $this;
- return new ScopedCallback( $this->profileOutCallback, array( $that, $section ) );
+ return new SectionProfileCallback( $this, $section );
}
/**
}
}
}
+
+/**
+ * Subclass ScopedCallback to avoid call_user_func_array(), which is slow
+ *
+ * This class should not be used outside of SectionProfiler
+ */
+class SectionProfileCallback extends ScopedCallback {
+ /** @var SectionProfiler */
+ protected $profiler;
+ /** @var string */
+ protected $section;
+
+ /**
+ * @param SectionProfiler $profiler
+ * @param string $section
+ */
+ public function __construct( SectionProfiler $profiler, $section ) {
+ parent::__construct( null );
+ $this->profiler = $profiler;
+ $this->section = $section;
+ }
+
+ function __destruct() {
+ $this->profiler->profileOutInternal( $this->section );
+ }
+}