RowSnapshot.jsm 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*******************************************************************************
  2. ηMatrix - a browser extension to black/white list requests.
  3. Copyright (C) 2014-2019 Raymond Hill
  4. Copyright (C) 2019-2020-2021 Alessio Vanni
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see {http://www.gnu.org/licenses/}.
  15. Home: https://gitlab.com/vannilla/ematrix
  16. uMatrix Home: https://github.com/gorhill/uMatrix
  17. */
  18. 'use strict';
  19. // Apparently, for this specific data structure using a constructor is
  20. // faster than an object literal.
  21. // I don't really believe it, but let's keep things as they are.
  22. // Now a module to keep things more organized (might make things slower.)
  23. var EXPORTED_SYMBOLS = ['RowSnapshot'];
  24. var RowSnapshot = function (matrix, src, dest, domain) {
  25. this.domain = domain;
  26. this.temporary = matrix.tMatrix.evaluateRowZXY(src, dest);
  27. this.permanent = matrix.pMatrix.evaluateRowZXY(src, dest);
  28. this.counts = RowSnapshot.counts(matrix).slice();
  29. this.totals = RowSnapshot.counts(matrix).slice();
  30. };
  31. RowSnapshot.memoizedCounts = undefined;
  32. RowSnapshot.counts = function (matrix) {
  33. if (RowSnapshot.memoizedCounts !== undefined) {
  34. return RowSnapshot.memoizedCounts;
  35. }
  36. let aa = [];
  37. let n = matrix.Matrix.columnHeaderIndices.size;
  38. for (let i=0; i<n; ++i) {
  39. aa[i] = 0;
  40. }
  41. RowSnapshot.memoizedCounts = aa;
  42. return aa;
  43. };