mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +01:00
Add a slice.suffix method.
This commit is contained in:
1 parent
51f2b183a2
commit
2fb9972bb9
10 files changed
+176
-2
No files matched your search
@@ -324,6 +324,45 @@ extern int printf(const char* __restrict __format, ...);
|
||||
#define PUFFS_UNLIKELY(expr) (expr)
|
||||
#endif
|
||||
|
||||
// ---------------- Static Inline Functions
|
||||
//
|
||||
// The helpers below are functions, instead of macros, because their arguments
|
||||
// can be an expression that we shouldn't evaluate more than once.
|
||||
//
|
||||
// They are in base-impl.h and hence copy/pasted into every generated C file,
|
||||
// instead of being in some "base.c" file, since a design goal is that users of
|
||||
// the generated C code can often just #include a single .c file, such as
|
||||
// "gif.c", without having to additionally include or otherwise build and link
|
||||
// a "base.c" file.
|
||||
//
|
||||
// They are static, so that linking multiple puffs .o files won't complain about
|
||||
// duplicate function definitions.
|
||||
//
|
||||
// They are explicitly marked inline, even if modern compilers don't use the
|
||||
// inline attribute to guide optimizations such as inlining, to avoid the
|
||||
// -Wunused-function warning, and we like to compile with -Wall -Werror.
|
||||
|
||||
// puffs_base_slice_u8_prefix returns up to the first n bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(
|
||||
puffs_base_slice_u8 s,
|
||||
uint64_t n) {
|
||||
if ((uint64_t)(s.len) > n) {
|
||||
s.len = n;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_suffix returns up to the last n bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
puffs_base_slice_u8 s,
|
||||
uint64_t n) {
|
||||
if ((uint64_t)(s.len) > n) {
|
||||
s.ptr += (uint64_t)(s.len) - n;
|
||||
s.len = n;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // PUFFS_BASE_IMPL_H
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
@@ -589,6 +628,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
||||
v_written = ((puffs_base_slice_u8){.ptr = a_dst.buf->ptr,
|
||||
.len = b_wptr_dst - a_dst.buf->ptr});
|
||||
if (((uint64_t)(v_written.len)) >= 32768) {
|
||||
v_written = puffs_base_slice_u8_suffix(v_written, 32768);
|
||||
}
|
||||
}
|
||||
status = v_z;
|
||||
|
||||
@@ -297,6 +297,45 @@ extern int printf(const char* __restrict __format, ...);
|
||||
#define PUFFS_UNLIKELY(expr) (expr)
|
||||
#endif
|
||||
|
||||
// ---------------- Static Inline Functions
|
||||
//
|
||||
// The helpers below are functions, instead of macros, because their arguments
|
||||
// can be an expression that we shouldn't evaluate more than once.
|
||||
//
|
||||
// They are in base-impl.h and hence copy/pasted into every generated C file,
|
||||
// instead of being in some "base.c" file, since a design goal is that users of
|
||||
// the generated C code can often just #include a single .c file, such as
|
||||
// "gif.c", without having to additionally include or otherwise build and link
|
||||
// a "base.c" file.
|
||||
//
|
||||
// They are static, so that linking multiple puffs .o files won't complain about
|
||||
// duplicate function definitions.
|
||||
//
|
||||
// They are explicitly marked inline, even if modern compilers don't use the
|
||||
// inline attribute to guide optimizations such as inlining, to avoid the
|
||||
// -Wunused-function warning, and we like to compile with -Wall -Werror.
|
||||
|
||||
// puffs_base_slice_u8_prefix returns up to the first n bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(
|
||||
puffs_base_slice_u8 s,
|
||||
uint64_t n) {
|
||||
if ((uint64_t)(s.len) > n) {
|
||||
s.len = n;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_suffix returns up to the last n bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
puffs_base_slice_u8 s,
|
||||
uint64_t n) {
|
||||
if ((uint64_t)(s.len) > n) {
|
||||
s.ptr += (uint64_t)(s.len) - n;
|
||||
s.len = n;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // PUFFS_BASE_IMPL_H
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
Reference in new issue
Block a user