Commit 61804943f4b6b4de2788055875ea7ef3f77c63b1

Authored by m-holger
1 parent 2f4c1d38

Add new private header file InputSource_private.hh

Move qpdf private inline methods to private header file.
include/qpdf/InputSource.hh
... ... @@ -75,7 +75,7 @@ class QPDF_DLL_CLASS InputSource
75 75 // semantically equivalent to seek(-1, SEEK_CUR) but is much more efficient.
76 76 virtual void unreadCh(char ch) = 0;
77 77  
78   - // The following methods are for use by QPDFTokenizer
  78 + // The following methods are for internal use by qpdf only.
79 79 inline qpdf_offset_t fastTell();
80 80 inline bool fastRead(char&);
81 81 inline void fastUnread(bool);
... ... @@ -93,57 +93,4 @@ class QPDF_DLL_CLASS InputSource
93 93 qpdf_offset_t buf_start = 0;
94 94 };
95 95  
96   -inline void
97   -InputSource::loadBuffer()
98   -{
99   - this->buf_idx = 0;
100   - this->buf_len = qpdf_offset_t(read(this->buffer, this->buf_size));
101   - // NB read sets last_offset
102   - this->buf_start = this->last_offset;
103   -}
104   -
105   -inline qpdf_offset_t
106   -InputSource::fastTell()
107   -{
108   - if (this->buf_len == 0) {
109   - loadBuffer();
110   - } else {
111   - auto curr = tell();
112   - if (curr < this->buf_start || curr >= (this->buf_start + this->buf_len)) {
113   - loadBuffer();
114   - } else {
115   - this->last_offset = curr;
116   - this->buf_idx = curr - this->buf_start;
117   - }
118   - }
119   - return this->last_offset;
120   -}
121   -
122   -inline bool
123   -InputSource::fastRead(char& ch)
124   -{
125   - // Before calling fastRead, fastTell must be called to prepare the buffer. Once reading is
126   - // complete, fastUnread must be called to set the correct file position.
127   - if (this->buf_idx < this->buf_len) {
128   - ch = this->buffer[this->buf_idx];
129   - ++(this->buf_idx);
130   - ++(this->last_offset);
131   - return true;
132   -
133   - } else if (this->buf_len == 0) {
134   - return false;
135   - } else {
136   - seek(this->buf_start + this->buf_len, SEEK_SET);
137   - fastTell();
138   - return fastRead(ch);
139   - }
140   -}
141   -
142   -inline void
143   -InputSource::fastUnread(bool back)
144   -{
145   - this->last_offset -= back ? 1 : 0;
146   - seek(this->last_offset, SEEK_SET);
147   -}
148   -
149 96 #endif // QPDF_INPUTSOURCE_HH
... ...
libqpdf/InputSource.cc
1   -#include <qpdf/InputSource.hh>
  1 +#include <qpdf/InputSource_private.hh>
2 2  
3 3 #include <qpdf/QIntC.hh>
4 4 #include <qpdf/QTC.hh>
... ...
libqpdf/QPDFTokenizer.cc
... ... @@ -3,6 +3,7 @@
3 3 // DO NOT USE ctype -- it is locale dependent for some things, and it's not worth the risk of
4 4 // including it in case it may accidentally be used.
5 5  
  6 +#include <qpdf/InputSource_private.hh>
6 7 #include <qpdf/QIntC.hh>
7 8 #include <qpdf/QPDFExc.hh>
8 9 #include <qpdf/QPDFObjectHandle.hh>
... ...
libqpdf/qpdf/InputSource_private.hh 0 → 100644
  1 +#ifndef QPDF_INPUTSOURCE_PRIVATE_HH
  2 +#define QPDF_INPUTSOURCE_PRIVATE_HH
  3 +
  4 +#include <qpdf/InputSource.hh>
  5 +
  6 +inline void
  7 +InputSource::loadBuffer()
  8 +{
  9 + buf_idx = 0;
  10 + buf_len = qpdf_offset_t(read(buffer, buf_size));
  11 + // NB read sets last_offset
  12 + buf_start = last_offset;
  13 +}
  14 +
  15 +inline qpdf_offset_t
  16 +InputSource::fastTell()
  17 +{
  18 + if (buf_len == 0) {
  19 + loadBuffer();
  20 + } else {
  21 + auto curr = tell();
  22 + if (curr < buf_start || curr >= (buf_start + buf_len)) {
  23 + loadBuffer();
  24 + } else {
  25 + last_offset = curr;
  26 + buf_idx = curr - buf_start;
  27 + }
  28 + }
  29 + return last_offset;
  30 +}
  31 +
  32 +inline bool
  33 +InputSource::fastRead(char& ch)
  34 +{
  35 + // Before calling fastRead, fastTell must be called to prepare the buffer. Once reading is
  36 + // complete, fastUnread must be called to set the correct file position.
  37 + if (buf_idx < buf_len) {
  38 + ch = buffer[buf_idx];
  39 + ++(buf_idx);
  40 + ++(last_offset);
  41 + return true;
  42 +
  43 + } else if (buf_len == 0) {
  44 + return false;
  45 + } else {
  46 + seek(buf_start + buf_len, SEEK_SET);
  47 + fastTell();
  48 + return fastRead(ch);
  49 + }
  50 +}
  51 +
  52 +inline void
  53 +InputSource::fastUnread(bool back)
  54 +{
  55 + last_offset -= back ? 1 : 0;
  56 + seek(last_offset, SEEK_SET);
  57 +}
  58 +
  59 +#endif // QPDF_INPUTSOURCE_PRIVATE_HH
... ...