From dc56c4e530f19310ce1b8925e89b4167c1df898c Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Tue, 20 Sep 2016 10:30:09 +0200 Subject: [PATCH] bptr.h: size optimizations. --- src/bptr.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/bptr.h b/src/bptr.h index 8b64ce63..d0466e2a 100644 --- a/src/bptr.h +++ b/src/bptr.h @@ -77,19 +77,31 @@ public: private: void checkNULL() const { - if (!ptr_) + if __acc_very_unlikely(!ptr_) throwCantUnpack("unexpected NULL pointer; take care!"); } - void checkRange(size_t extra=0) const { + void checkRange() const { size_t off = (const char *) ptr_ - (const char *) base_; - if (off > size_ || off + extra > size_) + if __acc_very_unlikely(off > size_) throwCantUnpack("pointer out of range; take care!"); } - void checkStrict(size_t extra=0) const { + void checkRange(size_t extra) const { + size_t off = (const char *) ptr_ - (const char *) base_; + if __acc_very_unlikely(off > size_ || off + extra > size_) + throwCantUnpack("pointer out of range; take care!"); + } + void checkStrict() const { + checkNULL(); + checkRange(); + } + void checkStrict(size_t extra) const { checkNULL(); checkRange(extra); } - void check(size_t extra=0) const { + void check() const { + if (ptr_) checkRange(); + } + void check(size_t extra) const { if (ptr_) checkRange(extra); }