<commit_before>import Transform from '../Transform';
import {inherits} from 'vega-util';

/**
 * Sorts data tuples in the pulse source array.
 * @constructor
 * @param {object} params - The parameters for this operator.
 * @param {function(*,*): number} [params.sort] - A comparator
 *   function for sorting tuples.
 */
export default function Sort(params) {
  Transform.call(this, null, params);
}

var prototype = inherits(Sort, Transform);

prototype.transform = function(_, pulse) {
  this.modified(_.modified('sort') || pulse.changed()
    ? (pulse.source.sort(_.sort), true)
    : false);

  return pulse;
};
<commit_msg>Make Sort transform more efficient.<commit_after>import Transform from '../Transform';
import {inherits} from 'vega-util';

/**
 * Sorts data tuples in the pulse source array.
 * @constructor
 * @param {object} params - The parameters for this operator.
 * @param {function(*,*): number} [params.sort] - A comparator
 *   function for sorting tuples.
 */
export default function Sort(params) {
  Transform.call(this, null, params);
}

var prototype = inherits(Sort, Transform);

prototype.transform = function(_, pulse) {
  var mod = _.modified('sort')
         || pulse.changed(pulse.ADD)
         || pulse.modified(_.sort.fields);

  if (mod) pulse.source.sort(_.sort);

  this.modified(mod);
  return pulse;
};

{'fraction_non_alphanumeric': 0.146795827123696, 'fraction_numerical': 0.0, 'mean_word_length': 3.992565055762082, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3357779', 'n_tokens_mistral': 408, 'n_tokens_neox': 390, 'n_words': 120}