Skip to content
Snippets Groups Projects
Select Git revision
  • a04ed8135db57ffe2e507cd77e35b5ca12b6eb3d
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

short-string-pool.ts

Blame
  • short-string-pool.ts 778 B
    /**
     * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * from https://github.com/dsehnal/CIFTools.js
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    /**
     * This ensures there is only 1 instance of a short string.
     * Also known as string interning, see https://en.wikipedia.org/wiki/String_interning
     */
    interface ShortStringPool { [key: string]: string }
    namespace ShortStringPool {
        export function create(): ShortStringPool { return Object.create(null); }
        export function get(pool: ShortStringPool, str: string) {
            if (str.length > 6) return str;
            const value = pool[str];
            if (value !== void 0) return value;
            pool[str] = str;
            return str;
        }
    }
    
    export default ShortStringPool;