Skip to content

Commit bd6ddf9

Browse files
authored
Merge pull request tplgy#65 from jpetso/master
Fix a recent warning and ensure inlining for less-smart compilers.
2 parents 26ae528 + 322e526 commit bd6ddf9

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

cppcodec/data/raw_result_buffer.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ class raw_result_buffer
4141
{
4242
}
4343

44-
char last() const { return *(m_ptr - 1); }
45-
void push_back(char c) { *m_ptr = c; ++m_ptr; }
46-
size_t size() const { return m_ptr - m_begin; }
47-
void resize(size_t size) { m_ptr = m_begin + size; }
44+
CPPCODEC_ALWAYS_INLINE void push_back(char c) { *m_ptr = c; ++m_ptr; }
45+
CPPCODEC_ALWAYS_INLINE size_t size() const { return m_ptr - m_begin; }
46+
CPPCODEC_ALWAYS_INLINE void resize(size_t size) { m_ptr = m_begin + size; }
4847

4948
private:
5049
char* m_ptr;
@@ -56,7 +55,7 @@ template <> inline void init<raw_result_buffer>(
5655
raw_result_buffer& result, empty_result_state&, size_t capacity)
5756
{
5857
// This version of init() doesn't do a reserve(), and instead checks whether the
59-
// initial size (capacity) is enough before resizing to 0.
58+
// initial size (capacity) is enough before resetting m_ptr to m_begin.
6059
// The codec is expected not to exceed this capacity.
6160
if (capacity > result.size()) {
6261
abort();

cppcodec/detail/stream_codec.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ class stream_codec
5353

5454
template <bool GeneratesPadding> // default for CodecVariant::generates_padding() == false
5555
struct padder {
56-
template <typename CodecVariant, typename Result, typename ResultState, typename EncodedBlockSizeT>
57-
CPPCODEC_ALWAYS_INLINE void operator()(Result&, ResultState&, EncodedBlockSizeT) { }
56+
template <typename CodecVariant, typename Result, typename ResultState, typename SizeT>
57+
static CPPCODEC_ALWAYS_INLINE void pad(Result&, ResultState&, SizeT) { }
5858
};
5959

6060
template<> // specialization for CodecVariant::generates_padding() == true
6161
struct padder<true> {
62-
template <typename CodecVariant, typename Result, typename ResultState, typename EncodedBlockSizeT>
63-
CPPCODEC_ALWAYS_INLINE void operator()(
64-
Result& encoded, ResultState& state, EncodedBlockSizeT num_padding_characters)
62+
template <typename CodecVariant, typename Result, typename ResultState, typename SizeT>
63+
static CPPCODEC_ALWAYS_INLINE void pad(
64+
Result& encoded, ResultState& state, SizeT num_padding_characters)
6565
{
66-
for (EncodedBlockSizeT i = 0; i < num_padding_characters; ++i) {
66+
for (SizeT i = 0; i < num_padding_characters; ++i) {
6767
data::put(encoded, state, CodecVariant::padding_symbol());
6868
}
6969
}
@@ -93,12 +93,6 @@ struct enc {
9393

9494
if (num_symbols == NumSymbols) {
9595
data::put(encoded, state, CodecVariant::symbol(Codec::template index_last<SymbolIndex>(src)));
96-
padder<CodecVariant::generates_padding()> pad;
97-
#ifdef _MSC_VER
98-
pad.operator()<CodecVariant>(encoded, state, Codec::encoded_block_size() - NumSymbols);
99-
#else
100-
pad.template operator()<CodecVariant>(encoded, state, Codec::encoded_block_size() - NumSymbols);
101-
#endif
10296
return;
10397
}
10498
data::put(encoded, state, CodecVariant::symbol(Codec::template index<SymbolIndex>(src)));
@@ -144,8 +138,14 @@ inline void stream_codec<Codec, CodecVariant>::encode(
144138
abort();
145139
return;
146140
}
147-
auto num_symbols = Codec::num_encoded_tail_symbols(static_cast<uint8_t>(remaining_src_len));
141+
142+
auto num_symbols = Codec::num_encoded_tail_symbols(
143+
static_cast<uint8_t>(remaining_src_len));
144+
148145
encoder::template tail<Codec, CodecVariant>(encoded_result, state, src, num_symbols);
146+
147+
padder<CodecVariant::generates_padding()>::template pad<CodecVariant>(
148+
encoded_result, state, Codec::encoded_block_size() - num_symbols);
149149
}
150150
}
151151

0 commit comments

Comments
 (0)