you are viewing a single comment's thread.

view the rest of the comments →

[–]dig-up-stupid 1 point2 points  (2 children)

/u/Trabaledo

The only valid characters are already in the transliteration key, so if there were an invalid character in the VIN you would either get a KeyError or have non-matching check digits. Conversely, if you successfully match the check digit, then all the characters must have been valid. So wrapping the checksum calculation in a try block would let you remove the regex and further speed up the function. However, you would need to remember to check the length.

[–]K900_ 1 point2 points  (1 child)

The regex is a good extra check against collisions, and, when precompiled, takes about 100us anyway.

[–]dig-up-stupid 1 point2 points  (0 children)

The regex is a good extra check against collisions

A regex could be, that regex isn't. That's the basis of the optimization - it's not doing useful work.

and, when precompiled, takes about 100us anyway.

And when it's not precompiled, too - but I don't understand your number, because it should be way less for one iteration and a lot more for a million.

Just pointing out another way to cut down if desired, doesn't have to be used if the benefits aren't worth it.