This tiny refactoring PR replaces all occurences of sizeof(x)/sizeof(x[0])
(or sizeof(x)/sizeof(*x)
, respectively) with the macro ARRAYLEN(x)
. While the pattern to determine the array of a length is a very common one and should be familiar for every C or C++ programmer, I think readability is still improved if it is hidden behind a macro. And since we have already ARRAYLEN
in the codebase since the beginning (indeed Satoshi already had it in v0.1.0, see https://github.com/trottier/original-bitcoin/blob/master/src/util.h#L27), why not use it consistently?
The instances to replace were discovered via
$ grep -Ir "sizeof.*/.*sizeof" src/*
If this gets a Concept ACK, one could probably discuss if the header strencodings.h
is really the right location for this macro – it doesn’t have anything to do with strings at all. Maybe util/macro.h
would be a more appropriate place.