Browse Source

better el symb cache

David Sehnal 7 years ago
parent
commit
41135331a9
2 changed files with 23 additions and 6 deletions
  1. 19 2
      src/mol-data/structure/model/types.ts
  2. 4 4
      src/perf-tests/structure.ts

+ 19 - 2
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 {

+ 4 - 4
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]);