This is an archive of the discontinued LLVM Phabricator instance.

Support: Add llvm::center_justify.
ClosedPublic

Authored by marsupial on Jul 11 2017, 3:05 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

marsupial created this revision.Jul 11 2017, 3:05 PM
ruiu added a subscriber: ruiu.Jul 11 2017, 3:17 PM
ruiu added inline comments.
include/llvm/Support/Format.h
132 ↗(On Diff #106103)

Why don't you use Justification as a type? I think you don't need to save a few bits here.

lib/Support/raw_ostream.cpp
334–343 ↗(On Diff #106103)

Using an enum value as a bitmask looks too tricky. It is probably better to write in three-way branches like this.

switch (FS.Justify) {
case JustifyRight:
  this->indent(FS.Width - Len);
  this->operator<<(FS.Str);
  break;
case JustifyCenter: {
  int PadAmount = (FS.Width - Len) / 2;
  this->indent(PadAmount);
  this->operator<<(FS.Str);  
  this->indent(Difference - PadAmount * 2);
}
case JustifyLeft:
  this->operator<<(FS.Str);
  this->indent(FS.Width - Len);
  break;
}
marsupial updated this revision to Diff 106111.Jul 11 2017, 4:01 PM
marsupial marked 2 inline comments as done.

Ok,

ruiu added inline comments.Jul 11 2017, 4:08 PM
lib/Support/raw_ostream.cpp
344 ↗(On Diff #106111)

nit; since the scope of this variable is very small, I wouldn't add const as it is obvious.

347 ↗(On Diff #106111)
PadAmount + (Difference - (PadAmount * 2))

is the same as

PadAmount + Difference - PadAmount * 2

and thus

Difference - PadAmount

?

348 ↗(On Diff #106111)

I believe we usually write this way.

  break;
}
marsupial updated this revision to Diff 106115.Jul 11 2017, 4:35 PM
ruiu added inline comments.Jul 11 2017, 4:39 PM
lib/Support/raw_ostream.cpp
347 ↗(On Diff #106111)

Isn't this the same as Difference - PadAmount as I wrote above?

marsupial updated this revision to Diff 106117.Jul 11 2017, 4:44 PM
marsupial marked an inline comment as done.

Updated

ruiu added a comment.Jul 11 2017, 4:47 PM

It looks good to me, but I'll LGTM tomorrow to give other reviewers a chance to take a look.

ruiu accepted this revision.Jul 12 2017, 11:14 AM

LGTM

This revision is now accepted and ready to land.Jul 12 2017, 11:14 AM
This revision was automatically updated to reflect the committed changes.
marsupial marked 3 inline comments as done.