Skip to content

Commit

Permalink
Avoid unnecessary calls to realpath().
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Aug 28, 2020
1 parent 46fe29a commit c9f84bd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
8 changes: 6 additions & 2 deletions filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ open_altfile(filename, pf, pfd)
int f;

/*
* The first time we open the file, read one char
* The alt file is a pipe. Read one char
* to see if the pipe will produce any data.
* If it does, push the char back on the pipe.
*/
Expand All @@ -924,18 +924,22 @@ open_altfile(filename, pf, pfd)
*/
int status = pclose(fd);
if (returnfd > 1 && status == 0) {
/* File is empty. */
*pfd = NULL;
*pf = -1;
return (save(FAKE_EMPTYFILE));
}
/* No alt file. */
return (NULL);
}
/* Alt pipe contains data, so use it. */
ch_ungetchar(c);
*pfd = (void *) fd;
*pf = f;
return (save("-"));
}
#endif
/* The alt file is a regular file. Read its name from LESSOPEN. */
cmd = readfd(fd);
pclose(fd);
if (*cmd == '\0')
Expand Down Expand Up @@ -965,7 +969,7 @@ close_altfile(altfilename, filename)
return;
ch_ungetchar(-1);
if ((lessclose = lgetenv("LESSCLOSE")) == NULL)
return;
return;
if (num_pct_s(lessclose) > 2)
{
error("LESSCLOSE ignored; must contain no more than 2 %%s", NULL_PARG);
Expand Down
14 changes: 13 additions & 1 deletion ifile.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ get_ifile(filename, prev)
}

/*
* Get the filename associated with a ifile.
* Get the display filename associated with a ifile.
*/
public char *
get_filename(ifile)
Expand All @@ -266,6 +266,18 @@ get_filename(ifile)
return (int_ifile(ifile)->h_filename);
}

/*
* Get the canonical filename associated with a ifile.
*/
public char *
get_real_filename(ifile)
IFILE ifile;
{
if (ifile == NULL)
return (NULL);
return (int_ifile(ifile)->h_rfilename);
}

/*
* Get the index of the file associated with a ifile.
*/
Expand Down
5 changes: 2 additions & 3 deletions mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ mark_check_ifile(ifile)
IFILE ifile;
{
int i;
char *filename = lrealpath(get_filename(ifile));
char *filename = get_real_filename(ifile);

for (i = 0; i < NMARKS; i++)
{
Expand Down Expand Up @@ -406,8 +406,7 @@ save_marks(fout, hdr)
postoa(m->m_scrpos.pos, pos_str);
filename = m->m_filename;
if (filename == NULL)
filename = get_filename(m->m_ifile);
filename = lrealpath(filename);
filename = get_real_filename(m->m_ifile);
if (strcmp(filename, "-") != 0)
fprintf(fout, "m %c %d %s %s\n",
m->m_letter, m->m_scrpos.ln, pos_str, filename);
Expand Down

0 comments on commit c9f84bd

Please sign in to comment.