qtools_profiler-8.x-1.x-dev/src/XHProfLib/Parser/SymbolsSorter.php

src/XHProfLib/Parser/SymbolsSorter.php
<?php

namespace Drupal\qtools_profiler\XHProfLib\Parser;

/**
 * Class SymbolsSorter
 */
class SymbolsSorter {

  private static $metric;

  /**
   * @param $symbols
   * @param $metric
   */
  static function sort(&$symbols, $metric) {
    self::$metric = $metric;
    uasort($symbols, array(
      "Drupal\\qtools_profiler\\XHProfLib\\Parser\\SymbolsSorter",
      "cmp_method"
    ));
  }

  /**
   * @param $a
   * @param $b
   *
   * @return int
   */
  static function cmp_method($a, $b) {
    $metric = self::$metric;

    if ($metric == "fn") {

      // case insensitive ascending sort for function names
      $left = strtoupper($a["fn"]);
      $right = strtoupper($b["fn"]);

      if ($left == $right) {
        return 0;
      }

      return ($left < $right) ? -1 : 1;
    }
    else {
      // descending sort for all others
      $left = $a[$metric];
      $right = $b[$metric];

      if ($left == $right) {
        return 0;
      }
      return ($left > $right) ? -1 : 1;
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc