Files
react-native/local-cli/server/middleware/heapCapture/src/StringInterner.js
Charles Dick 48d3cd7d26 Pull aggrow from facebookincubator/tracery-prerelease
Reviewed By: bnham

Differential Revision: D4250937

fbshipit-source-id: b5f2cfdeb06c04399670e463b8b2498e2fe0074b
2016-11-30 12:58:35 -08:00

27 lines
461 B
JavaScript

// @flow
type InternedStringsTable = {
[key: string]: number,
}
export default class StringInterner {
strings: Array<string> = [];
ids: InternedStringsTable = {};
intern(s: string): number {
const find = this.ids[s];
if (find === undefined) {
const id = this.strings.length;
this.ids[s] = id;
this.strings.push(s);
return id;
}
return find;
}
get(id: number): string {
return this.strings[id];
}
}