shared-strings.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  5. var SharedStrings = /*#__PURE__*/function () {
  6. function SharedStrings() {
  7. _classCallCheck(this, SharedStrings);
  8. this._values = [];
  9. this._totalRefs = 0;
  10. this._hash = Object.create(null);
  11. }
  12. _createClass(SharedStrings, [{
  13. key: "getString",
  14. value: function getString(index) {
  15. return this._values[index];
  16. }
  17. }, {
  18. key: "add",
  19. value: function add(value) {
  20. var index = this._hash[value];
  21. if (index === undefined) {
  22. index = this._hash[value] = this._values.length;
  23. this._values.push(value);
  24. }
  25. this._totalRefs++;
  26. return index;
  27. }
  28. }, {
  29. key: "count",
  30. get: function get() {
  31. return this._values.length;
  32. }
  33. }, {
  34. key: "values",
  35. get: function get() {
  36. return this._values;
  37. }
  38. }, {
  39. key: "totalRefs",
  40. get: function get() {
  41. return this._totalRefs;
  42. }
  43. }]);
  44. return SharedStrings;
  45. }();
  46. module.exports = SharedStrings;
  47. //# sourceMappingURL=shared-strings.js.map