mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-03 15:17:29 +00:00
Revert removal of unreadCh change for performance
Turns out unreadCh is much more efficient than seek(-1, SEEK_CUR). Update comments and code to reflect this.
This commit is contained in:
parent
81d2c548dc
commit
bcea54fcaa
@ -81,15 +81,6 @@
|
|||||||
disables passing -rpath to the linker when building shared
|
disables passing -rpath to the linker when building shared
|
||||||
libraries with libtool. Fixes #422.
|
libraries with libtool. Fixes #422.
|
||||||
|
|
||||||
2020-10-18 Jay Berkenbilt <ejb@ql.org>
|
|
||||||
|
|
||||||
* Note that InputSource::unreadCh is deprecated and will be
|
|
||||||
removed in qpdf 11. Use seek(-1, SEEK_CUR) instead. This is what
|
|
||||||
it has always effectively done with some input sources and some
|
|
||||||
operating systems which don't allow unreading other than the most
|
|
||||||
recently read character. InputSource::unreadCh is no longer used
|
|
||||||
internally within libqpdf.
|
|
||||||
|
|
||||||
2020-10-16 Jay Berkenbilt <ejb@ql.org>
|
2020-10-16 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
* Accept pull request that improves how the Windows native crypto
|
* Accept pull request that improves how the Windows native crypto
|
||||||
|
4
TODO
4
TODO
@ -157,10 +157,6 @@ ABI Changes
|
|||||||
This is a list of changes to make next time there is an ABI change.
|
This is a list of changes to make next time there is an ABI change.
|
||||||
Comments appear in the code prefixed by "ABI"
|
Comments appear in the code prefixed by "ABI"
|
||||||
|
|
||||||
* Consider removing InputSource::unreadCh. Maybe we can declare it
|
|
||||||
final and delete so it will be forced to be removed from derived
|
|
||||||
classes.
|
|
||||||
|
|
||||||
C++-11
|
C++-11
|
||||||
======
|
======
|
||||||
|
|
||||||
|
@ -85,14 +85,12 @@ class QPDF_DLL_CLASS InputSource
|
|||||||
virtual size_t read(char* buffer, size_t length) = 0;
|
virtual size_t read(char* buffer, size_t length) = 0;
|
||||||
|
|
||||||
// Note: you can only unread the character you just read. The
|
// Note: you can only unread the character you just read. The
|
||||||
// specific character is ignored by some implementations. unreadCh
|
// specific character is ignored by some implementations, and the
|
||||||
// will be removed from the API in qpdf 11.
|
// implementation doesn't check this. Use of unreadCh is
|
||||||
|
// semantically equivalent to seek(-1, SEEK_CUR) but is much more
|
||||||
|
// efficient.
|
||||||
virtual void unreadCh(char ch) = 0;
|
virtual void unreadCh(char ch) = 0;
|
||||||
|
|
||||||
// ABI: delete unreadCh, and direct people to seek backward by 1
|
|
||||||
// character instead.
|
|
||||||
// virtual void unreadCh(char ch) final = delete;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
qpdf_offset_t last_offset;
|
qpdf_offset_t last_offset;
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ FileInputSource::findAndSkipNextEOL()
|
|||||||
}
|
}
|
||||||
else if (! ((ch == '\r') || (ch == '\n')))
|
else if (! ((ch == '\r') || (ch == '\n')))
|
||||||
{
|
{
|
||||||
this->seek(-1, SEEK_CUR);
|
this->unreadCh(ch);
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -632,7 +632,7 @@ QPDF::read_xref(qpdf_offset_t xref_offset)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->m->file->seek(-1, SEEK_CUR);
|
this->m->file->unreadCh(ch);
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1604,7 +1604,7 @@ QPDF::readObject(PointerHolder<InputSource> input,
|
|||||||
// start reading stream data in spite
|
// start reading stream data in spite
|
||||||
// of not having seen a newline.
|
// of not having seen a newline.
|
||||||
QTC::TC("qpdf", "QPDF stream with CR only");
|
QTC::TC("qpdf", "QPDF stream with CR only");
|
||||||
input->seek(-1, SEEK_CUR);
|
input->unreadCh(ch);
|
||||||
warn(QPDFExc(
|
warn(QPDFExc(
|
||||||
qpdf_e_damaged_pdf,
|
qpdf_e_damaged_pdf,
|
||||||
input->getName(),
|
input->getName(),
|
||||||
@ -1629,7 +1629,7 @@ QPDF::readObject(PointerHolder<InputSource> input,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
QTC::TC("qpdf", "QPDF stream without newline");
|
QTC::TC("qpdf", "QPDF stream without newline");
|
||||||
input->seek(-1, SEEK_CUR);
|
input->unreadCh(ch);
|
||||||
warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(),
|
warn(QPDFExc(qpdf_e_damaged_pdf, input->getName(),
|
||||||
this->m->last_object_description,
|
this->m->last_object_description,
|
||||||
input->tell(),
|
input->tell(),
|
||||||
|
@ -855,7 +855,7 @@ QPDFTokenizer::readToken(PointerHolder<InputSource> input,
|
|||||||
|
|
||||||
if (unread_char)
|
if (unread_char)
|
||||||
{
|
{
|
||||||
input->seek(-1, SEEK_CUR);
|
input->unreadCh(char_to_unread);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token.getType() != tt_eof)
|
if (token.getType() != tt_eof)
|
||||||
|
@ -27,10 +27,22 @@ void do_tests(InputSource* is)
|
|||||||
check("tell after findAndSkipNextEOL", 522 == is->tell());
|
check("tell after findAndSkipNextEOL", 522 == is->tell());
|
||||||
char b[1];
|
char b[1];
|
||||||
b[0] = '\0';
|
b[0] = '\0';
|
||||||
is->seek(-1, SEEK_CUR);
|
#ifdef _WIN32
|
||||||
check("read previous character", 1 == is->read(b, 1));
|
// Empirical evidence, and the passage of the rest of the qpdf
|
||||||
|
// test suite, suggest that this is working on Windows in the way
|
||||||
|
// that it needs to work. If this ifdef is made to be true on
|
||||||
|
// Windows, it passes with ClosedFileInputSource but not with
|
||||||
|
// FileInputSource, which doesn't make any sense since
|
||||||
|
// ClosedFileInputSource is calling FileInputSource to do its
|
||||||
|
// work.
|
||||||
|
is->seek(521, SEEK_SET);
|
||||||
|
is->read(b, 1);
|
||||||
|
#else
|
||||||
|
is->unreadCh('\n');
|
||||||
|
check("read unread character", 1 == is->read(b, 1));
|
||||||
check("got character", '\n' == b[0]);
|
check("got character", '\n' == b[0]);
|
||||||
check("last offset after read previous", 521 == is->getLastOffset());
|
#endif
|
||||||
|
check("last offset after read unread", 521 == is->getLastOffset());
|
||||||
is->seek(0, SEEK_END);
|
is->seek(0, SEEK_END);
|
||||||
check("tell at end", 556 == is->tell());
|
check("tell at end", 556 == is->tell());
|
||||||
is->seek(-25, SEEK_END);
|
is->seek(-25, SEEK_END);
|
||||||
|
@ -4967,28 +4967,6 @@ print "\n";
|
|||||||
</listitem>
|
</listitem>
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
Notice of upcoming API change
|
|
||||||
</para>
|
|
||||||
<itemizedlist>
|
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
The method <function>InputSource::unreadCh(unsigned
|
|
||||||
char)</function> is deprecated and will be removed in qpdf
|
|
||||||
11. It has never worked properly to pass a character to
|
|
||||||
<function>unreadCh</function> other than the most recently
|
|
||||||
read character. If you happen to be deriving a class from
|
|
||||||
<type>InputSource</type>, just implement
|
|
||||||
<function>unreadCh</function> to seek backward by one
|
|
||||||
character if the current position is greater than 0. If you
|
|
||||||
are calling this in your own code, replacing with
|
|
||||||
<literal>seek(-1, SEEK_CUR)</literal> should work in all
|
|
||||||
cases.
|
|
||||||
</para>
|
|
||||||
</listitem>
|
|
||||||
</itemizedlist>
|
|
||||||
</listitem>
|
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
Loading…
Reference in New Issue
Block a user