math/mptext.c: Radically refactor `mp_read'.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 14 Oct 2015 10:00:51 +0000 (11:00 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 14 Oct 2015 16:08:17 +0000 (17:08 +0100)
commita6b6ae6baba64bf876bac6e4d34b364035666183
treeb04e5b185fefce90a8adc3e933cfd257766bac23
parent626cd971624f0804d7b0ddada5168553c955aa64
math/mptext.c: Radically refactor `mp_read'.

It used to be the largest function in the library -- possibly in my
codebase.

  * Split it into three main pieces: the special-purpose binary reader,
    an efficient stack-based general-radix reader, and a high-level
    syntax parser which picks out signs and base indicators.  This
    removes the complicated entangling of the base indicator parsing
    with the general-radix reader which was the worst feature of the old
    version.

  * Split commonly-used functionality out into separate functions,
    notably `char_digit' and `read_digit'.

The result is code which is easier to understand and actually shorter.
math/mptext.c