4 ms·
In this case, there is an alternative view to 'architecture astronaut': Conservative programming. If you don't have experience with the spec, it might not be c
by hyperman1 5y ago
In this case, there is an alternative view to 'architecture astronaut': Conservative programming. If you don't have experience with the spec, it might not be clear that n<=4 is the reasonable maximum if the spec permits n=255. Who knows what horrible JPGs exist in the wild? Even if you only find examples to test n<=4, are you willing to take the risk ignoring what's left? Your code needs to be out in the real world for a while before you can truly say. Better a slow but working implementation.
- _0ffh 5y agoGP explicitly covered this: Just expand your fixed-size array to the required size, it's still not a big array. It solves the exact problem, the map is overkill and overly complicated. The problem is, the map is only more complicated in the resulting binary, not in the library users' source code.
- eru 5y agoNot sure the binary comes into it. The map in this language has a more complicated API than the array (because iteration is a bit more complicated).
- samus 5y agoAllocating 255 elements is not the end of the world. Unless the decoder is supposed to run on a memory-constrained platform, this is barely noticeable.