This is an archive of the discontinued LLVM Phabricator instance.

Replace redundant code in FormatManager and FormatCache with templates (NFC)
ClosedPublic

Authored by aprantl on Dec 9 2019, 4:21 PM.

Details

Summary

This is a preparatory patch for an upcoming bugfix.

FormatManager and friends have four identical implementations of many accessor functions to deal with the four types of shared pointers in the FormatCache. This patch replaces these implementations with templates. While this patch drastically reduces the amount of source code and its maintainablity, it doesn't actually improve code size. I'd argue, this is still an improvement.

Diff Detail

Event Timeline

aprantl created this revision.Dec 9 2019, 4:21 PM

Not really my area, but it seems reasonable. One thing I'd consider is replacing the functions which return the values through a by-ref argument (e.g. TypeCategoryMap::Get with an actual return value. That'd mean one would have to type out the type in the invocation explicitly instead of relying on template argument deduction, but I don't think that's very useful, as one still has to spell out the type in the variable declaration on the preceding line..

aprantl updated this revision to Diff 233134.Dec 10 2019, 10:02 AM

Make (most) of the Get methods return return values, as Pavel suggested.

This revision was not accepted when it landed; it landed in state Needs Review.Dec 10 2019, 10:27 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptDec 10 2019, 10:28 AM