This is an archive of the discontinued LLVM Phabricator instance.

Teach llvm::format_hex() to support formatting without a prefix '0x'
ClosedPublic

Authored by zturner on Jan 23 2015, 11:52 AM.

Details

Summary

Simple change, hope someone can take a look.

When you're dumping single bytes, having '0x' on the front of every byte is difficult to read and doubles the size of the output.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner updated this revision to Diff 18687.Jan 23 2015, 11:52 AM
zturner retitled this revision from to Teach llvm::format_hex() to support formatting without a prefix '0x'.
zturner updated this object.
zturner edited the test plan for this revision. (Show Details)
zturner added reviewers: rnk, majnemer.
zturner added a subscriber: Unknown Object (MLST).
majnemer edited edge metadata.Jan 23 2015, 12:11 PM

Why not just use llvm::utohexstr?

Why not just use llvm::utohexstr?

Isn't that less efficient than just writing directly to the stream? Results in one heap allocation for every byte.

rnk added inline comments.Jan 23 2015, 1:38 PM
include/llvm/Support/Format.h
278–279 ↗(On Diff #18687)

I'd rather have a special purpose helper than a second default value bool. format_hex_noprefix? format_noprefix_hex? format_hex_bytes?

zturner added inline comments.Jan 23 2015, 1:43 PM
include/llvm/Support/Format.h
278–279 ↗(On Diff #18687)

I agree in principle that default values suck, but on the other hand I don't think HexPrefix is any more or less special than Upper, aside from having been implemented later. So it's inconsistent that one of the options is specified via a default argument, while another option is specified by using a different function even though there's nothing fundamentally different about the two options. Something like this would be a good time for a flags enum, but that would require updating thousands of lines of code.

Another thing is that it makes the pre-function comment showing sample inputs and outputs a little redundant now. I guess I would just copy over all 4 samples but remove the 0x from each of them?

Either way, I don't feel too strongly, so I don't mind changing it.

zturner updated this revision to Diff 18699.Jan 23 2015, 4:52 PM
zturner edited edge metadata.

Moved the no-prefix option to a separate function. Also added a test.

This revision was automatically updated to reflect the committed changes.