Telephone 2.0.0: Clear Rules, Fewer Allocations
A phone number consists of a few digits, perhaps a plus sign, and occasionally an extension. What’s so slow about that? With this reassuring question, you can put off launching a profiler for a surprisingly long time.
My telephone library processes national and international phone numbers as well as number ranges. The formatter architecture is based on an older Java formatter implementation: A pattern is first broken down into small parser and formatting modules, which then work together to get the job done. This is flexible, easy to understand, and, for starters, a good foundation.
But even with a proven architecture, it’s worth taking a closer look. So when I checked the runtime and memory usage, I took a closer look. The result: a few avoidable allocations, three parser errors, and a new major version. So “I’ll just tidy things up a bit” turned into a small software project. We’ve all been there.