<commit_before>//
// Like testTwo, but instead of simply replacing the nodes
// we first clone them. This leads to a single DOM op instead
// of `n+1` DOM ops.
//

(function() {
  var btn = document.querySelector('#test3');

  btn.addEventListener('click', function() {

    // Create our list, and append it to the test node
    var $list = $('<ul></ul>');
    var lis = new Array(10000);
    for(var i=0; i<lis.length; i++) {
      var $li = $('<li></li>').addClass('l'+i);
      lis[i] = $li;
      $list.append($li);
    }
    test.$el.append($list);

    // Rather than create a new tree from a template, I'm going ahead and cloning it
    var $listClone = $list.clone();

    // Kick off the test
    test.start('three');

    // Loop through the children in the cloned tree, replacing
    // them with cloned versions of the elements in the existing
    // tree. This causes 0 ops
    $listClone.children().each(function(index, li) {
      $(li).replaceWith(lis[index]);
    });

    // The only op is the replace
    test.$el.find('ul').append($listClone.contents());

    test.stop();
  });
})();<commit_msg>Use cloning. Sorry, screwed that up.<commit_after>//
// Like testTwo, but instead of simply replacing the nodes
// we first clone them. This leads to a single DOM op instead
// of `n+1` DOM ops.
//

(function() {
  var btn = document.querySelector('#test3');

  btn.addEventListener('click', function() {

    // Create our list, and append it to the test node
    var $list = $('<ul></ul>');
    var lis = new Array(10000);
    for(var i=0; i<lis.length; i++) {
      var $li = $('<li></li>').addClass('l'+i);
      lis[i] = $li;
      $list.append($li);
    }
    test.$el.append($list);

    // Rather than create a new tree from a template, I'm going ahead and cloning it
    var $listClone = $list.clone();

    // Kick off the test
    test.start('three');

    // Loop through the children in the cloned tree, replacing
    // them with cloned versions of the elements in the existing
    // tree. This causes 0 ops
    $listClone.children().each(function(index, li) {
      $(li).replaceWith(lis[index].clone(true));
    });

    // The only op is the replace
    test.$el.find('ul').empty().append($listClone);

    test.stop();
  });
})();
{'fraction_non_alphanumeric': 0.16593115622241836, 'fraction_numerical': 0.00794351279788173, 'mean_word_length': 2.747107438016529, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '5235455', 'n_tokens_mistral': 732, 'n_tokens_neox': 693, 'n_words': 241}