shared-strings.js 648 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. class SharedStrings {
  3. constructor() {
  4. this._values = [];
  5. this._totalRefs = 0;
  6. this._hash = Object.create(null);
  7. }
  8. get count() {
  9. return this._values.length;
  10. }
  11. get values() {
  12. return this._values;
  13. }
  14. get totalRefs() {
  15. return this._totalRefs;
  16. }
  17. getString(index) {
  18. return this._values[index];
  19. }
  20. add(value) {
  21. let index = this._hash[value];
  22. if (index === undefined) {
  23. index = this._hash[value] = this._values.length;
  24. this._values.push(value);
  25. }
  26. this._totalRefs++;
  27. return index;
  28. }
  29. }
  30. module.exports = SharedStrings;
  31. //# sourceMappingURL=shared-strings.js.map