[varLib.featureVars] Optimize popCount()
While might look like unjustified micro-optimizing, for featureVars_test.py with n=100, speeds up 10%. From 2.5s to 2.2s.
This commit is contained in:
parent
0283b1fd1d
commit
0be1636176
@ -73,13 +73,13 @@ class hashdict(dict):
|
||||
return result
|
||||
|
||||
def popCount(v):
|
||||
# TODO Speed up
|
||||
i = 0
|
||||
while v:
|
||||
if v & 1:
|
||||
i += 1
|
||||
v = v >> 1
|
||||
return i
|
||||
if v > 0xFFFFFFFF:
|
||||
return popCount(v >> 32) + popCount(v & 0xFFFFFFFF)
|
||||
|
||||
# HACKMEM 169
|
||||
y = (v >> 1) & 033333333333
|
||||
y = v - y - ((y >> 1) & 033333333333)
|
||||
return (((y + (y >> 3)) & 030707070707) % 077)
|
||||
|
||||
|
||||
def addFeatureVariations(font, conditionalSubstitutions):
|
||||
|
Loading…
x
Reference in New Issue
Block a user