mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-02 09:21:44 +08:00
Reviewed By: bnham Differential Revision: D4250937 fbshipit-source-id: b5f2cfdeb06c04399670e463b8b2498e2fe0074b
27 lines
461 B
JavaScript
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];
|
|
}
|
|
}
|