Skip to content

Commit

Permalink
Remove forced inlining from fast streams.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Jan 29, 2024
1 parent 5179513 commit c474676
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 65 deletions.
30 changes: 15 additions & 15 deletions include/bitcoin/system/impl/stream/iostream/iostream.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ BC_PUSH_WARNING(NO_POINTER_ARITHMETIC)

template <typename Character>
template <typename Buffer>
INLINE iostream<Character>::iostream(Buffer& buffer) NOEXCEPT
iostream<Character>::iostream(Buffer& buffer) NOEXCEPT
: position_(buffer.data()),
begin_(position_),
end_(begin_ + buffer.size()),
Expand All @@ -37,7 +37,7 @@ INLINE iostream<Character>::iostream(Buffer& buffer) NOEXCEPT
}

template <typename Character>
INLINE iostream<Character>::iostream(uint8_t* begin,
iostream<Character>::iostream(uint8_t* begin,
ptrdiff_t size) NOEXCEPT
: position_(begin),
begin_(position_),
Expand All @@ -47,43 +47,43 @@ INLINE iostream<Character>::iostream(uint8_t* begin,
}

template <typename Character>
INLINE typename iostream<Character>::iostate
inline typename iostream<Character>::iostate
iostream<Character>::rdstate() const NOEXCEPT
{
return state_;
}

template <typename Character>
INLINE void
inline void
iostream<Character>::setstate(iostate state) NOEXCEPT
{
state_ |= state;
}

template <typename Character>
INLINE void
inline void
iostream<Character>::clear(iostate state) NOEXCEPT
{
state_ = state;
}


template <typename Character>
INLINE typename iostream<Character>::pos_type
inline typename iostream<Character>::pos_type
iostream<Character>::tellg() const NOEXCEPT
{
return static_cast<pos_type>(position_ - begin_);
}

template <typename Character>
INLINE typename iostream<Character>::pos_type
inline typename iostream<Character>::pos_type
iostream<Character>::tellp() const NOEXCEPT
{
return static_cast<pos_type>(position_ - begin_);
}

template <typename Character>
INLINE iostream<Character>&
iostream<Character>&
iostream<Character>::seekg(off_type offset, seekdir direction) NOEXCEPT
{
if (state_ != goodbit)
Expand Down Expand Up @@ -137,7 +137,7 @@ iostream<Character>::seekg(off_type offset, seekdir direction) NOEXCEPT
}

template <typename Character>
INLINE typename iostream<Character>::int_type
typename iostream<Character>::int_type
iostream<Character>::peek() NOEXCEPT
{
constexpr auto eof = std::char_traits<Character>::eof();
Expand All @@ -153,7 +153,7 @@ iostream<Character>::peek() NOEXCEPT
}

template <typename Character>
INLINE void
void
iostream<Character>::read(char_type* data, pos_type size) NOEXCEPT
{
if (is_overflow(size))
Expand All @@ -170,7 +170,7 @@ iostream<Character>::read(char_type* data, pos_type size) NOEXCEPT
}

template <typename Character>
INLINE void
void
iostream<Character>::write(const char_type* data,
pos_type size) NOEXCEPT
{
Expand All @@ -181,14 +181,14 @@ iostream<Character>::write(const char_type* data,
}

BC_PUSH_WARNING(NO_UNSAFE_COPY_N)
std::copy_n(data, size, position_);
std::copy_n(data, size, position_);
BC_POP_WARNING()

position_ += size;
position_ += size;
}

template <typename Character>
INLINE void
void
iostream<Character>::flush() NOEXCEPT
{
}
Expand All @@ -203,7 +203,7 @@ iostream<Character>::is_positive(off_type value) NOEXCEPT

// private
template <typename Character>
INLINE bool
bool
iostream<Character>::is_overflow(pos_type size) const NOEXCEPT
{
return (state_ != goodbit) || (size > (end_ - position_));
Expand Down
21 changes: 10 additions & 11 deletions include/bitcoin/system/impl/stream/iostream/istream.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BC_PUSH_WARNING(NO_POINTER_ARITHMETIC)

template <typename Character>
template <typename Buffer>
INLINE istream<Character>::istream(const Buffer& buffer) NOEXCEPT
istream<Character>::istream(const Buffer& buffer) NOEXCEPT
: position_(buffer.data()),
begin_(position_),
end_(begin_ + buffer.size()),
Expand All @@ -39,8 +39,7 @@ INLINE istream<Character>::istream(const Buffer& buffer) NOEXCEPT
}

template <typename Character>
INLINE istream<Character>::istream(const uint8_t* begin,
ptrdiff_t size) NOEXCEPT
istream<Character>::istream(const uint8_t* begin, ptrdiff_t size) NOEXCEPT
: position_(begin),
begin_(position_),
end_(begin_ + size),
Expand All @@ -49,35 +48,35 @@ INLINE istream<Character>::istream(const uint8_t* begin,
}

template <typename Character>
INLINE typename istream<Character>::iostate
inline typename istream<Character>::iostate
istream<Character>::rdstate() const NOEXCEPT
{
return state_;
}

template <typename Character>
INLINE void
inline void
istream<Character>::setstate(iostate state) NOEXCEPT
{
state_ |= state;
}

template <typename Character>
INLINE void
inline void
istream<Character>::clear(iostate state) NOEXCEPT
{
state_ = state;
}

template <typename Character>
INLINE typename istream<Character>::pos_type
inline typename istream<Character>::pos_type
istream<Character>::tellg() const NOEXCEPT
{
return static_cast<pos_type>(position_ - begin_);
}

template <typename Character>
INLINE istream<Character>&
istream<Character>&
istream<Character>::seekg(off_type offset, seekdir direction) NOEXCEPT
{
if (state_ != goodbit)
Expand Down Expand Up @@ -131,7 +130,7 @@ istream<Character>::seekg(off_type offset, seekdir direction) NOEXCEPT
}

template <typename Character>
INLINE typename istream<Character>::int_type
typename istream<Character>::int_type
istream<Character>::peek() NOEXCEPT
{
constexpr auto eof = std::char_traits<Character>::eof();
Expand All @@ -147,7 +146,7 @@ istream<Character>::peek() NOEXCEPT
}

template <typename Character>
INLINE void
void
istream<Character>::read(char_type* data, pos_type size) NOEXCEPT
{
if (is_overflow(size))
Expand All @@ -173,7 +172,7 @@ istream<Character>::is_positive(off_type value) NOEXCEPT

// private
template <typename Character>
INLINE bool
bool
istream<Character>::is_overflow(pos_type size) const NOEXCEPT
{
return (state_ != goodbit) || (size > (end_ - position_));
Expand Down
14 changes: 7 additions & 7 deletions include/bitcoin/system/impl/stream/iostream/ostream.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,35 @@ ostream<Character>::ostream(uint8_t* begin,
}

template <typename Character>
INLINE typename ostream<Character>::iostate
inline typename ostream<Character>::iostate
ostream<Character>::rdstate() const NOEXCEPT
{
return state_;
}

template <typename Character>
INLINE void
inline void
ostream<Character>::setstate(iostate state) NOEXCEPT
{
state_ |= state;
}

template <typename Character>
INLINE void
inline void
ostream<Character>::clear(iostate state) NOEXCEPT
{
state_ = state;
}

template <typename Character>
INLINE typename ostream<Character>::pos_type
inline typename ostream<Character>::pos_type
ostream<Character>::tellp() const NOEXCEPT
{
return static_cast<pos_type>(position_ - begin_);
}

template <typename Character>
INLINE void
void
ostream<Character>::write(const char_type* data,
pos_type size) NOEXCEPT
{
Expand All @@ -94,14 +94,14 @@ ostream<Character>::write(const char_type* data,
}

template <typename Character>
INLINE void
void
ostream<Character>::flush() NOEXCEPT
{
}

// private
template <typename Character>
INLINE bool
bool
ostream<Character>::is_overflow(pos_type size) const NOEXCEPT
{
return (state_ != goodbit) || (size > (end_ - position_));
Expand Down
26 changes: 13 additions & 13 deletions include/bitcoin/system/stream/iostream/iostream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,42 @@ class iostream

/// Construct the object.
template <typename Buffer>
INLINE iostream(Buffer& buffer) NOEXCEPT;
INLINE iostream(uint8_t* begin, ptrdiff_t size) NOEXCEPT;
iostream(Buffer& buffer) NOEXCEPT;
iostream(uint8_t* begin, ptrdiff_t size) NOEXCEPT;

/// Return state flags.
virtual INLINE iostate rdstate() const NOEXCEPT;
virtual inline iostate rdstate() const NOEXCEPT;

/// Set the stream error flags state in addition to currently set flags.
virtual INLINE void setstate(iostate state) NOEXCEPT;
virtual inline void setstate(iostate state) NOEXCEPT;

/// Set the stream error state flags by assigning the state value.
virtual INLINE void clear(iostate state = goodbit) NOEXCEPT;
virtual inline void clear(iostate state = goodbit) NOEXCEPT;

/// Return the relative input position indicator (zero-based).
virtual INLINE pos_type tellg() const NOEXCEPT;
virtual inline pos_type tellg() const NOEXCEPT;

/// Return the relative output position indicator (zero-based).
virtual INLINE pos_type tellp() const NOEXCEPT;
virtual inline pos_type tellp() const NOEXCEPT;

/// Set the relative input position indicator (zero-based).
virtual INLINE iostream& seekg(off_type offset, seekdir direction) NOEXCEPT;
virtual iostream& seekg(off_type offset, seekdir direction) NOEXCEPT;

/// Read the next character without advancing, sets badbit on underflow.
virtual INLINE int_type peek() NOEXCEPT;
virtual int_type peek() NOEXCEPT;

/// Read a block of characters, sets badbit on underflow.
virtual INLINE void read(char_type* data, pos_type size) NOEXCEPT;
virtual void read(char_type* data, pos_type size) NOEXCEPT;

/// Write a block of characters, sets badbit on overflow.
virtual INLINE void write(const char_type* data, pos_type size) NOEXCEPT;
virtual void write(const char_type* data, pos_type size) NOEXCEPT;

/// Synchronize with the underlying storage device (no-op).
virtual INLINE void flush() NOEXCEPT;
virtual void flush() NOEXCEPT;

private:
static constexpr bool is_positive(off_type value) NOEXCEPT;
INLINE bool is_overflow(pos_type size) const NOEXCEPT;
bool is_overflow(pos_type size) const NOEXCEPT;

uint8_t* position_;
uint8_t* begin_;
Expand Down
20 changes: 10 additions & 10 deletions include/bitcoin/system/stream/iostream/istream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,33 @@ class istream

/// Construct the object.
template <typename Buffer>
INLINE istream(const Buffer& buffer) NOEXCEPT;
INLINE istream(const uint8_t* begin, ptrdiff_t size) NOEXCEPT;
istream(const Buffer& buffer) NOEXCEPT;
istream(const uint8_t* begin, ptrdiff_t size) NOEXCEPT;

/// Return state flags.
virtual INLINE iostate rdstate() const NOEXCEPT;
virtual inline iostate rdstate() const NOEXCEPT;

/// Set the stream error flags state in addition to currently set flags.
virtual INLINE void setstate(iostate state) NOEXCEPT;
virtual inline void setstate(iostate state) NOEXCEPT;

/// Set the stream error state flags by assigning the state value.
virtual INLINE void clear(iostate state=goodbit) NOEXCEPT;
virtual inline void clear(iostate state=goodbit) NOEXCEPT;

/// Return the relative input position indicator (zero-based).
virtual INLINE pos_type tellg() const NOEXCEPT;
virtual inline pos_type tellg() const NOEXCEPT;

/// Set the relative input position indicator (zero-based).
virtual INLINE istream& seekg(off_type offset, seekdir direction) NOEXCEPT;
virtual istream& seekg(off_type offset, seekdir direction) NOEXCEPT;

/// Read the next character without advancing, sets badbit on underflow.
virtual INLINE int_type peek() NOEXCEPT;
virtual int_type peek() NOEXCEPT;

/// Read a block of characters, sets badbit on underflow.
virtual INLINE void read(char_type* data, pos_type size) NOEXCEPT;
virtual void read(char_type* data, pos_type size) NOEXCEPT;

private:
static constexpr bool is_positive(off_type value) NOEXCEPT;
INLINE bool is_overflow(pos_type size) const NOEXCEPT;
bool is_overflow(pos_type size) const NOEXCEPT;

const uint8_t* position_;
const uint8_t* begin_;
Expand Down
Loading

0 comments on commit c474676

Please sign in to comment.