This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Partially revert r322749, replacing array with DenseSet
AbandonedPublic

Authored by krasimir on Mar 20 2018, 11:31 AM.

Details

Summary

The array + binary_search requires the initializer list of identifiers to be
sorted. I can imagine how this list might change frequently while the support
for ObjectiveC improves (D44632). The array approach might have been a premature
optimization too, since in any case computing a hash for every token is trivial
compared to what we do for formatting it.

Diff Detail

Event Timeline

krasimir created this revision.Mar 20 2018, 11:31 AM
bkramer accepted this revision.Mar 20 2018, 11:36 AM

I wouldn't say that this is more maintainable, but I'm not the maintainer of clang-format.

This revision is now accepted and ready to land.Mar 20 2018, 11:36 AM
benhamilton added a comment.EditedMar 20 2018, 12:10 PM

I'm fine with whichever approach we use, but I'll defer to @djasper here.

(I'm not fully sure why llvm::DenseSet is better than std::unsorted_set, but I'm sure @djasper and @krasimir understand the subtleties better than I do.)

benhamilton resigned from this revision.Mar 20 2018, 12:10 PM

One way in which DenseSet is better is that it supports StringRefs - we don't have to define hash. Seems like the lack of this override in core LLVM suggests that unordered_set is not commonly used with StringRefs.

One way in which DenseSet is better is that it supports StringRefs - we don't have to define hash. Seems like the lack of this override in core LLVM suggests that unordered_set is not commonly used with StringRefs.

Makes sense, thanks.

krasimir abandoned this revision.May 18 2018, 2:46 AM