Perform fewer allocations in summarize_protocol_flags()

According to our profiles, summarize_protocol_flags() does a huge number of allocations -- probably because it parses the same flags over and over.

Probably it would be simplest just to memoize the output.