aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-06-21 10:53:17 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-06-21 10:53:17 +0000
commite8d78b17f19c8fada6f66effc463305651a71197 (patch)
treecdcc2e57c3496111bc5ae134c3758d5111cae742 /vespalib
parent6e14406b30bd27b4a82f94d4ff61e5e4cfb52757 (diff)
Inline hot path and keep error handling in .cpp file.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/compress.cpp40
-rw-r--r--vespalib/src/vespa/vespalib/util/compress.h30
2 files changed, 39 insertions, 31 deletions
diff --git a/vespalib/src/vespa/vespalib/util/compress.cpp b/vespalib/src/vespa/vespalib/util/compress.cpp
index ed237da1b28..75bb9bb8f40 100644
--- a/vespalib/src/vespa/vespalib/util/compress.cpp
+++ b/vespalib/src/vespa/vespalib/util/compress.cpp
@@ -6,19 +6,6 @@
namespace vespalib::compress {
-size_t Integer::compressedPositiveLength(uint64_t n)
-{
- if (n < (0x1 << 6)) {
- return 1;
- } else if (n < (0x1 << 14)) {
- return 2;
- } else if ( n < (0x1 << 30)) {
- return 4;
- } else {
- throw IllegalArgumentException(make_string("Number '%" PRIu64 "' too big, must extend encoding", n));
- }
-}
-
size_t Integer::compressPositive(uint64_t n, void *destination)
{
uint8_t * d = static_cast<uint8_t *>(destination);
@@ -37,24 +24,19 @@ size_t Integer::compressPositive(uint64_t n, void *destination)
d[3] = n & 0xff;
return 4;
} else {
- throw IllegalArgumentException(make_string("Number '%" PRIu64 "' too big, must extend encoding", n));
+ too_big(n);
}
}
-size_t Integer::compressedLength(int64_t n)
-{
- if (n < 0) {
- n = -n;
- }
- if (n < (0x1 << 5)) {
- return 1;
- } else if (n < (0x1 << 13)) {
- return 2;
- } else if ( n < (0x1 << 29)) {
- return 4;
- } else {
- throw IllegalArgumentException(make_string("Number '%" PRId64 "' too big, must extend encoding", n));
- }
+
+void
+Integer::too_big(int64_t n) {
+ throw IllegalArgumentException(make_string("Number '%" PRId64 "' too big, must extend encoding", n));
+}
+
+void
+Integer::too_big(uint64_t n) {
+ throw IllegalArgumentException(make_string("Number '%" PRIu64 "' too big, must extend encoding", n));
}
size_t Integer::compress(int64_t n, void *destination)
@@ -78,7 +60,7 @@ size_t Integer::compress(int64_t n, void *destination)
d[3] = n & 0xff;
return 4;
} else {
- throw IllegalArgumentException(make_string("Number '%" PRId64 "' too big, must extend encoding", negative ? -n : n));
+ too_big(negative ? -n : n);
}
}
diff --git a/vespalib/src/vespa/vespalib/util/compress.h b/vespalib/src/vespa/vespalib/util/compress.h
index 8218a0a43db..880ca268f28 100644
--- a/vespalib/src/vespa/vespalib/util/compress.h
+++ b/vespalib/src/vespa/vespalib/util/compress.h
@@ -27,12 +27,35 @@ public:
* @param unsigned number to compute compressed size of in bytes.
* @return Will return the number of bytes this positive number will require
**/
- static size_t compressedPositiveLength(uint64_t n);
+ static size_t compressedPositiveLength(uint64_t n) {
+ if (n < (0x1 << 6)) {
+ return 1;
+ } else if (n < (0x1 << 14)) {
+ return 2;
+ } else if ( n < (0x1 << 30)) {
+ return 4;
+ } else {
+ too_big(n);
+ }
+ }
/**
* @param number to compute compressed size of in bytes.
* @return Will return the number of bytes this number will require
**/
- static size_t compressedLength(int64_t n);
+ static size_t compressedLength(int64_t n) {
+ if (n < 0) {
+ n = -n;
+ }
+ if (n < (0x1 << 5)) {
+ return 1;
+ } else if (n < (0x1 << 13)) {
+ return 2;
+ } else if ( n < (0x1 << 29)) {
+ return 4;
+ } else {
+ too_big(n);
+ }
+ }
/**
* Will decompress an integer.
* @param pointer to buffer. pointer is automatically advanced.
@@ -82,6 +105,9 @@ public:
}
return numbytes;
}
+private:
+ [[ noreturn ]] static void too_big(int64_t n);
+ [[ noreturn ]] static void too_big(uint64_t n);
};
}