<commit_before>export default function mergeDiff(keys, nextKeys) {
  const order = {};
  for (let i = 0; i < keys.length; i++) {
    order[keys[i]] = i;
  }

  const nextOrder = {};
  for (let i = 0; i < nextKeys.length; i++) {
    nextOrder[nextKeys[i]] = i;
  }

  let prefix = [];
  let currentSegment = prefix;
  const segments = {};
  for (let i = 0; i < keys.length; i++) {
    if (nextOrder.hasOwnProperty(keys[i])) {
      segments[keys[i]] = [];
      currentSegment = segments[keys[i]];
    } else {
      currentSegment.push(keys[i]);
    }
  }

  let mergedKeys = prefix.slice();
  for (let i = 0; i < nextKeys.length; i++) {
    mergedKeys.push(nextKeys[i]);
    if (segments.hasOwnProperty(nextKeys[i])) {
      mergedKeys = mergedKeys.concat(segments[nextKeys[i]]);
    }
  }<commit_msg>remove old var<commit_after>export default function mergeDiff(keys, nextKeys) {
  const nextOrder = nextKeys.reduce((result, k, i) => {
    result[k] = i;
    return result;
  }, {});

  let prefix = [];
  let currentSegment = prefix;
  const segments = {};
  for (let i = 0; i < keys.length; i++) {
    if (nextOrder.hasOwnProperty(keys[i])) {
      segments[keys[i]] = [];
      currentSegment = segments[keys[i]];
    } else {
      currentSegment.push(keys[i]);
    }
  }

  let mergedKeys = prefix.slice();
  for (let i = 0; i < nextKeys.length; i++) {
    mergedKeys.push(nextKeys[i]);
    if (segments.hasOwnProperty(nextKeys[i])) {
      mergedKeys = mergedKeys.concat(segments[nextKeys[i]]);
    }
  }
{'fraction_non_alphanumeric': 0.17261904761904762, 'fraction_numerical': 0.003968253968253968, 'mean_word_length': 3.1114130434782608, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 4, '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': '5487851', 'n_tokens_mistral': 530, 'n_tokens_neox': 521, 'n_words': 115}