Skip to content

Commit

Permalink
Merge pull request #1693 from masatake/fmt-optimization
Browse files Browse the repository at this point in the history
xref-format: memorize format strings when parsing --xformat option
  • Loading branch information
masatake committed Feb 17, 2018
2 parents adf474c + 830b3c6 commit 66b4867
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions main/fmt.c
Expand Up @@ -25,7 +25,7 @@ typedef union uFmtSpec {
struct {
fieldType ftype;
int width;
bool truncation;
char *raw_fmtstr;
} field;
} fmtSpec;

Expand Down Expand Up @@ -85,11 +85,8 @@ static int printTagField (fmtSpec* fspec, MIO* fp, const tagEntryInfo * tag)
if (str == NULL)
str = "";

bool trunc = fspec->field.truncation;
if (width < 0)
i = mio_printf (fp, (trunc? "%-.*s": "%-*s"), -1 * width, str);
else if (width > 0)
i = mio_printf (fp, (trunc? "%.*s": "%*s"), width, str);
if (width)
i = mio_printf (fp, fspec->field.raw_fmtstr, width, str);
else
{
mio_puts (fp, str);
Expand Down Expand Up @@ -205,7 +202,16 @@ static fmtElement** queueTagField (fmtElement **last, long width, bool truncatio

cur->spec.field.width = width;
cur->spec.field.ftype = ftype;
cur->spec.field.truncation = truncation;

if (width < 0)
{
cur->spec.field.width *= -1;
cur->spec.field.raw_fmtstr = (truncation? "%-.*s": "%-*s");
}
else if (width > 0)
cur->spec.field.raw_fmtstr = (truncation? "%.*s": "%*s");
else
cur->spec.field.raw_fmtstr = NULL;

enableField (ftype, true, false);
if (language == LANG_AUTO)
Expand Down

0 comments on commit 66b4867

Please sign in to comment.