Re-introduce writer1.use_limit.

Nobody uses it yet, as we only decode and not encode, but it's there for
symmetry.

No benchmark changes, as nobody uses it yet.
This commit is contained in:
Nigel Tao committed 2017-11-02 16:46:03 +11:00
1 parent 7d8085f891
commit e5db8233fc
7 files changed
+10 -10

No files matched your search

+1 -1
View File
@@ -119,7 +119,7 @@ typedef struct {
// use_limit is redundant, in that it always equals (limit != NULL), but
// having a separate bool can have a significant performance effect with
// gcc 4.8.4 (e.g. 1.1x on some benchmarks).
// TODO: bool use_limit;
bool use_limit;
} private_impl;
} puffs_base__writer1;
+1 -1
View File
@@ -327,7 +327,7 @@ static inline puffs_base__empty_struct puffs_base__writer1__limit(
o->private_impl.limit = ptr + limit;
}
}
// TODO: o->private_impl.use_limit = true;
o->private_impl.use_limit = true;
return ((puffs_base__empty_struct){});
}
+2 -2
View File
@@ -21,7 +21,7 @@ const baseHeader = "" +
"milarly, the word size is at most 64 bits because it assumes that\n// converting a usize to u64 will never overflow.\n#if __WORDSIZE < 32\n#error \"Puffs requires a word size of at least 32 bits\"\n#elif __WORDSIZE > 64\n#error \"Puffs requires a word size of at most 64 bits\"\n#endif\n\n// PUFFS_VERSION is the major.minor version number as a uint32. The major\n// number is the high 16 bits. The minor number is the low 16 bits.\n//\n// The intention is to bump the version number at least on every API / ABI\n// backwards incompatible change.\n//\n// For now, the API and ABI are simply unstable and can change at any time.\n//\n// TODO: don't hard code this in base-header.h.\n#define PUFFS_VERSION (0x00001)\n\n// PUFFS_USE_NO_OP_PERFORMANCE_HACKS enables code paths that look like\n// redundant no-ops, but for reasons to be investigated, can have dramatic\n// performance effects with gcc 4.8.4 (e.g. 1.2x on some benchmarks).\n//\n// TODO: investigate; delete these hacks (without regressing performance).\n// The order matters here. Clang als" +
"o defines \"__GNUC__\".\n#if defined(__clang__)\n#elif defined(__GNUC__)\n#define PUFFS_USE_NO_OP_PERFORMANCE_HACKS 1\n#endif\n\n// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).\n//\n// A value with all fields NULL or zero is a valid, empty slice.\ntypedef struct {\n uint8_t* ptr;\n size_t len;\n} puffs_base__slice_u8;\n\n// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus\n// additional indexes into that buffer, plus an opened / closed flag.\n//\n// A value with all fields NULL or zero is a valid, empty buffer.\ntypedef struct {\n uint8_t* ptr; // Pointer.\n size_t len; // Length.\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n bool closed; // No further writes are expected.\n} puffs_base__buf1;\n\n#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS\ntypedef struct {\n void* always_null0;\n void* always_null1;\n} puffs_base__paired_nulls;\n#endif\n\ntypedef struct {\n // TODO: move buf into private_impl? As it is, it looks like u" +
"sers can modify\n // the buf field to point to a different buffer, which can turn the limit and\n // mark fields into dangling pointers.\n puffs_base__buf1* buf;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n uint8_t* limit;\n uint8_t* mark;\n // use_limit is redundant, in that it always equals (limit != NULL), but\n // having a separate bool can have a significant performance effect with\n // gcc 4.8.4 (e.g. 1.1x on some benchmarks).\n bool use_limit;\n#ifdef PUFFS_USE_NO_OP_PERFORMANCE_HACKS\n struct {\n puffs_base__paired_nulls* noph0;\n uint32_t noph1;\n } * no_op_performance_hacks;\n#endif\n } private_impl;\n} puffs_base__reader1;\n\ntypedef struct {\n // TODO: move buf into private_impl? As it is, it looks like users can modify\n // the buf field to point to a different buffer, which can turn the limit and\n // mark fields into dangling pointers.\n puffs_base__buf1* buf;\n // Do not access th" +
"e private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n uint8_t* limit;\n uint8_t* mark;\n // use_limit is redundant, in that it always equals (limit != NULL), but\n // having a separate bool can have a significant performance effect with\n // gcc 4.8.4 (e.g. 1.1x on some benchmarks).\n // TODO: bool use_limit;\n } private_impl;\n} puffs_base__writer1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
"e private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n uint8_t* limit;\n uint8_t* mark;\n // use_limit is redundant, in that it always equals (limit != NULL), but\n // having a separate bool can have a significant performance effect with\n // gcc 4.8.4 (e.g. 1.1x on some benchmarks).\n bool use_limit;\n } private_impl;\n} puffs_base__writer1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
""
const baseImpl = "" +
@@ -35,7 +35,7 @@ const baseImpl = "" +
"t++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t puffs_base__writer1__copy_from_reader32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n uint8_t** ptr_rptr,\n uint8_t* rend,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = length;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n uint8_t* rptr = *ptr_rptr;\n if (n > rend - rptr) {\n n = rend - rptr;\n }\n if (n > 0) {\n memmove(wptr, rptr, n);\n *ptr_wptr += n;\n *ptr_rptr += n;\n }\n return n;\n}\n\nstatic inline uint64_t puffs_base__writer1__copy_from_slice(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n puffs_base__slice_u8 src) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\nstatic inline uint32_t puffs_base__writer1__copy_from_slice32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n " +
" puffs_base__slice_u8 src,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\n// Note that the *__limit and *__mark methods are private (in base-impl.h) not\n// public (in base-header.h). We assume that, at the boundary between user code\n// and Puffs code, the reader1 and writer1's private_impl fields (including\n// limit and mark) are NULL. Otherwise, some internal assumptions break down.\n// For example, the limit field is represented as a pointer, even though\n// conceptually it is a count, but that pointer-to-count correspondence becomes\n// invalid if a buffer is re-used (e.g. on resuming a coroutine).\n//\n// Admittedly, some of the Puffs test code calls these methods, but that test\n// code is still Puffs code, not user code. Other Puffs test code modifies\n// private_impl fields directly.\n\nstatic inline puffs_base__" +
"empty_struct puffs_base__reader1__limit(\n puffs_base__reader1* o,\n uint8_t* ptr,\n uint64_t limit) {\n if (!o->buf) {\n o->private_impl.limit = NULL;\n } else {\n uint64_t len = o->buf->wi - o->buf->ri;\n if (limit > len) {\n limit = len;\n }\n if (!o->private_impl.limit || (limit < (o->private_impl.limit - ptr))) {\n o->private_impl.limit = ptr + limit;\n }\n }\n o->private_impl.use_limit = true;\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__reader1__mark(\n puffs_base__reader1* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__writer1__limit(\n puffs_base__writer1* o,\n uint8_t* ptr,\n uint64_t limit) {\n if (!o->buf) {\n o->private_impl.limit = NULL;\n } else {\n uint64_t len = o->buf->len - o->buf->wi;\n if (limit > len) {\n limit = len;\n }\n if (!o->private_impl.limit || (limit < (o->private_impl.limit - ptr" +
"))) {\n o->private_impl.limit = ptr + limit;\n }\n }\n // TODO: o->private_impl.use_limit = true;\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__writer1__mark(\n puffs_base__writer1* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((puffs_base__empty_struct){});\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" +
"))) {\n o->private_impl.limit = ptr + limit;\n }\n }\n o->private_impl.use_limit = true;\n return ((puffs_base__empty_struct){});\n}\n\nstatic inline puffs_base__empty_struct puffs_base__writer1__mark(\n puffs_base__writer1* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((puffs_base__empty_struct){});\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" +
""
type template_args_short_read struct {
+2 -2
View File
@@ -122,7 +122,7 @@ typedef struct {
// use_limit is redundant, in that it always equals (limit != NULL), but
// having a separate bool can have a significant performance effect with
// gcc 4.8.4 (e.g. 1.1x on some benchmarks).
// TODO: bool use_limit;
bool use_limit;
} private_impl;
} puffs_base__writer1;
@@ -681,7 +681,7 @@ static inline puffs_base__empty_struct puffs_base__writer1__limit(
o->private_impl.limit = ptr + limit;
}
}
// TODO: o->private_impl.use_limit = true;
o->private_impl.use_limit = true;
return ((puffs_base__empty_struct){});
}
+2 -2
View File
@@ -122,7 +122,7 @@ typedef struct {
// use_limit is redundant, in that it always equals (limit != NULL), but
// having a separate bool can have a significant performance effect with
// gcc 4.8.4 (e.g. 1.1x on some benchmarks).
// TODO: bool use_limit;
bool use_limit;
} private_impl;
} puffs_base__writer1;
@@ -628,7 +628,7 @@ static inline puffs_base__empty_struct puffs_base__writer1__limit(
o->private_impl.limit = ptr + limit;
}
}
// TODO: o->private_impl.use_limit = true;
o->private_impl.use_limit = true;
return ((puffs_base__empty_struct){});
}
+1 -1
View File
@@ -122,7 +122,7 @@ typedef struct {
// use_limit is redundant, in that it always equals (limit != NULL), but
// having a separate bool can have a significant performance effect with
// gcc 4.8.4 (e.g. 1.1x on some benchmarks).
// TODO: bool use_limit;
bool use_limit;
} private_impl;
} puffs_base__writer1;
+1 -1
View File
@@ -122,7 +122,7 @@ typedef struct {
// use_limit is redundant, in that it always equals (limit != NULL), but
// having a separate bool can have a significant performance effect with
// gcc 4.8.4 (e.g. 1.1x on some benchmarks).
// TODO: bool use_limit;
bool use_limit;
} private_impl;
} puffs_base__writer1;