From 41135331a9f51bb0f8b247a42e9057e99b7cebf9 Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Sat, 4 Nov 2017 10:42:12 +0100 Subject: [PATCH] better el symb cache --- src/mol-data/structure/model/types.ts | 21 +++++++++++++++++++-- src/perf-tests/structure.ts | 8 ++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/mol-data/structure/model/types.ts b/src/mol-data/structure/model/types.ts index 374a5392c..4a90f04c9 100644 --- a/src/mol-data/structure/model/types.ts +++ b/src/mol-data/structure/model/types.ts @@ -7,10 +7,27 @@ import BitFlags from 'mol-base/utils/bit-flags' -const _esCache = Object.create(null); +const _esCache = (function () { + const cache = Object.create(null); + const letters: string[] = []; + for (let i = 'A'.charCodeAt(0); i <= 'Z'.charCodeAt(0); i++) letters[letters.length] = String.fromCharCode(i); + for (let i = 'a'.charCodeAt(0); i <= 'z'.charCodeAt(0); i++) letters[letters.length] = String.fromCharCode(i); + for (let i = '0'.charCodeAt(0); i <= '9'.charCodeAt(0); i++) letters[letters.length] = String.fromCharCode(i); + + for (const k of letters) { + cache[k] = k.toUpperCase(); + for (const l of letters) { + cache[k + l] = (k + l).toUpperCase(); + for (const m of letters) { + cache[k + l + m] = (k + l + m).toUpperCase(); + } + } + } + return cache; +}()); export interface ElementSymbol extends String { '@type': 'element-symbol' } export function ElementSymbol(s: string): ElementSymbol { - return _esCache[s] || (_esCache[s] = s.toUpperCase()); + return _esCache[s] || s.toUpperCase(); } export const enum EntityType { diff --git a/src/perf-tests/structure.ts b/src/perf-tests/structure.ts index 613782de8..af1fa2f27 100644 --- a/src/perf-tests/structure.ts +++ b/src/perf-tests/structure.ts @@ -237,8 +237,8 @@ export namespace PropertyAccess { // } export async function run() { - const { structures, models } = await readCIF('./examples/1cbs_full.bcif'); - //const { structures, models } = await readCIF('e:/test/quick/1jj2_full.bcif'); + //const { structures, models } = await readCIF('./examples/1cbs_full.bcif'); + const { structures, models } = await readCIF('e:/test/quick/3j3q_full.bcif'); //const { structures, models } = await readCIF('e:/test/quick/3j3q_updated.cif'); // console.log(toMmCIFString('test', structures[0])); @@ -280,8 +280,8 @@ export namespace PropertyAccess { chainTest: Q.pred.inSet(P.chain.auth_asym_id, ['A', 'B', 'C', 'D']), residueTest: Q.pred.eq(P.residue.auth_comp_id, 'ALA') }); - const q0r = q(structures[0]); - console.log(toMmCIFString('test', Selection.union(q0r))); + // const q0r = q(structures[0]); + // console.log(toMmCIFString('test', Selection.union(q0r))); console.time('q1') q1(structures[0]); -- GitLab