Changeset 33107 for main

Show
Ignore:
Timestamp:
24.05.2019 17:09:27 (5 months ago)
Author:
ak19
Message:

Minor optimisation to the double for loop that depends on the ordering of the selections being in the order of the checkboxes, and the order of the checkboxes being in the order of the docList ids.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/berrybasket/berrycheckout.js

    r33106 r33107  
    123123    else { // Not deleting all berries, just a subset 
    124124        // Remove id of selected doc to be deleted from docList.         
    125         // No ordering of berry indexes according to the order they're added, 
    126         // So can't optimise comparison further than traversing the docList array in reverse 
     125        // Minor optimisation to double for loop, dependent on ordering of selected berries being 
     126        // in order of checkboxes (i.e. order of docList ids), and order of docList ids having 
     127        // the same order as the checkboxes 
     128        var searchForNextSelectedIdFromIndex = idsToDelete.length-1; 
    127129        for (var i = docList.length - 1; i >= 0; i--) { 
    128130        var berry = docList[i]; 
    129131        var berry_id = berry['collection'] + ":" + berry['name']; 
    130132         
    131         for(var j = 0; j < idsToDelete.length; j++) { 
     133        for(var j = searchForNextSelectedIdFromIndex; j >= 0; j--) { 
    132134            if(idsToDelete[j] == berry_id) { 
    133135            docList.splice(i, 1); // i indexes into docList, delete element i from docList 
     136            searchForNextSelectedIdFromIndex = j-1; 
    134137            break; 
    135138            }