Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UGLY CODE SIZE HACK #492

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

UGLY CODE SIZE HACK #492

wants to merge 1 commit into from

Commits on Jun 19, 2020

  1. UGLY CODE SIZE HACK

    On master, each events has an impl for TryFrom<&[u8]>. protocol::Event
    uses this impl to parse the event and then wrap it in the Event enum.
    This means that the result from the TryFrom implementation has to be
    copied into the Event enum and the generated code actually contains such
    a copy. Actually, it contains many such copy sequences, one per event.
    
    This commit changes the structure a bit. Each event gets a function
    ugly_hack(&[u8]) -> Result<Event, ParseError>. Thus, protocol::Event
    only has to figure out which event this is and then call that event's
    ugly_hack(). This function then immediately constructs an instance of
    Event, thus avoiding the copy-bytes-around in the caller.
    
    This commit changes the size of the stripped xclock_utc example in a
    release build from 503 KiB to 495 KiB. This is a reduction in binary
    size by about 2.5 %.
    
    The assembler code for the full library goes from 159662 to 158847 lines
    (0.5% less), but the object file (.o) keeps its size / does not change.
    
    You might notice from the function name "ugly_hack" that I am not really
    happy with this implementation. Instead, I wanted to check if the
    general approach has merits. Apparently it does.
    psychon committed Jun 19, 2020
    Configuration menu
    Copy the full SHA
    7b2ed2a View commit details
    Browse the repository at this point in the history