varnumJewelsInStones=function(J,S){if(!J||!S)return0;// empty string, fast returnleta=0|0,b=0|0,j=0|0,i=J.length,l=S.length,myJewels=0>>>0;do{j=J.charCodeAt(--i);if(j<0x60)a|=1<<(j-0x41);elseb|=1<<(j-0x61);}while(i);do{j=S.charCodeAt(--l);if(j<0x60)a&(1<<(j-0x41))&&++myJewels;elseb&(1<<(j-0x61))&&++myJewels;}while(l);returnmyJewels;};
This is basically just the fast ASM.js compatible form I guess. Not too sure if it will work though...
This is probably because all the optimisations you may do in JS land may be thrown to the bin once it touches native code. I Rust you have more control over the memory layout.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Possible idea with the jewels thing:
This makes heavy use of CPU caching, so should be quite fast for longer strings.
Could also use A and B types
This can be done entirely on the stack and registers, so avoids other possible slowdowns related to allocation. Only issue is that of shifting...
Another, even faster:
This is basically just the fast ASM.js compatible form I guess. Not too sure if it will work though...
Edit: leetcode.com/submissions/detail/23...
tl;dr not as fast
A similar thing works perfectly fine in rust, though.
leetcode.com/submissions/detail/23...
These are all so cool! Iām going to have to pick through them later š
This is probably because all the optimisations you may do in JS land may be thrown to the bin once it touches native code. I Rust you have more control over the memory layout.