summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-05-23 12:40:20 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-05-23 12:40:20 +0000
commit55579edd61d95b86c9a4ea40bf1df928f51f4fc3 (patch)
tree97315333f77cf8da09a0a544cb1cd96270d1be2e
parent6397911eb7f2aa0fe4612f541488dbcdf4f54136 (diff)
Inline small frequently called methods
-rw-r--r--searchlib/src/vespa/searchlib/util/rawbuf.cpp60
-rw-r--r--searchlib/src/vespa/searchlib/util/rawbuf.h39
2 files changed, 31 insertions, 68 deletions
diff --git a/searchlib/src/vespa/searchlib/util/rawbuf.cpp b/searchlib/src/vespa/searchlib/util/rawbuf.cpp
index 04d69544047..3af29d7eed5 100644
--- a/searchlib/src/vespa/searchlib/util/rawbuf.cpp
+++ b/searchlib/src/vespa/searchlib/util/rawbuf.cpp
@@ -1,32 +1,11 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "rawbuf.h"
-#include <vespa/vespalib/util/compress.h>
#include <cassert>
-#include <cstring>
#include <cstdlib>
namespace search {
-RawBuf::RawBuf(size_t size)
- : _bufStart(nullptr),
- _bufEnd(nullptr),
- _bufFillPos(nullptr),
- _bufDrainPos(nullptr)
-{
- if (size > 0) {
- _bufStart = static_cast<char *>(malloc(size));
- }
- _bufEnd = _bufStart + size;
- _bufDrainPos = _bufFillPos = _bufStart;
-}
-
-RawBuf::~RawBuf()
-{
- free(_bufStart);
-}
-
-
/**
* Allocate a new buffer at least as large as the parameter value,
* move any content to the new and delete the old buffer.
@@ -50,45 +29,6 @@ RawBuf::expandBuf(size_t needlen)
_bufEnd = _bufStart + size;
}
-
-/**
- * Put 'data' of 'len'gth into the buffer. If insufficient room,
- * make the buffer larger.
- */
-void
-RawBuf::append(const void *data, size_t len)
-{
- if (__builtin_expect(len != 0, true)) {
- ensureSize(len);
- memcpy(_bufFillPos, data, len);
- _bufFillPos += len;
- }
-}
-
-void
-RawBuf::append(uint8_t byte)
-{
- ensureSize(1);
- *_bufFillPos++ = byte;
-}
-
-void
-RawBuf::appendCompressedPositiveNumber(uint64_t n)
-{
- size_t len(vespalib::compress::Integer::compressedPositiveLength(n));
- ensureSize(len);
- _bufFillPos += vespalib::compress::Integer::compressPositive(n, _bufFillPos);
-}
-
-void
-RawBuf::appendCompressedNumber(int64_t n)
-{
- size_t len(vespalib::compress::Integer::compressedLength(n));
- ensureSize(len);
- _bufFillPos += vespalib::compress::Integer::compress(n, _bufFillPos);
-}
-
-
/**
* Compact any free space from the beginning of the buffer, by
* copying the contents to the start of the buffer.
diff --git a/searchlib/src/vespa/searchlib/util/rawbuf.h b/searchlib/src/vespa/searchlib/util/rawbuf.h
index 30018cb45c2..9ecfbc23c24 100644
--- a/searchlib/src/vespa/searchlib/util/rawbuf.h
+++ b/searchlib/src/vespa/searchlib/util/rawbuf.h
@@ -2,8 +2,9 @@
#pragma once
-#include <cstdint>
-#include <cstddef>
+#include <vespa/vespalib/util/compress.h>
+#include <cstring>
+#include <cstdlib>
namespace search {
/**
@@ -45,13 +46,35 @@ private:
public:
RawBuf(const RawBuf &) = delete;
RawBuf& operator=(const RawBuf &) = delete;
- explicit RawBuf(size_t size); // malloc-s given size, assigns to _bufStart
- ~RawBuf(); // Frees _bufStart, i.e. the char[].
+ explicit RawBuf(size_t size)
+ : _bufStart(static_cast<char *>(malloc(size))),
+ _bufEnd(_bufStart + size),
+ _bufFillPos(_bufStart),
+ _bufDrainPos(_bufStart)
+ { }
+ ~RawBuf() {
+ free(_bufStart);
+ } // Frees _bufStart, i.e. the char[].
- void append(const void *data, size_t len);
- void append(uint8_t byte);
- void appendCompressedPositiveNumber(uint64_t n);
- void appendCompressedNumber(int64_t n);
+ void append(const void *data, size_t len) {
+ if (__builtin_expect(len != 0, true)) {
+ ensureSize(len);
+ memcpy(_bufFillPos, data, len);
+ _bufFillPos += len;
+ }
+ }
+ void append(uint8_t byte) {
+ ensureSize(1);
+ *_bufFillPos++ = byte;
+ }
+ void appendCompressedPositiveNumber(uint64_t n) {
+ ensureSize(vespalib::compress::Integer::compressedPositiveLength(n));
+ _bufFillPos += vespalib::compress::Integer::compressPositive(n, _bufFillPos);
+ }
+ void appendCompressedNumber(int64_t n) {
+ ensureSize(vespalib::compress::Integer::compressedLength(n));
+ _bufFillPos += vespalib::compress::Integer::compress(n, _bufFillPos);
+ }
size_t GetFreeLen() const { return _bufEnd - _bufFillPos; }
const char *GetDrainPos() const { return _bufDrainPos; }
char * GetWritableFillPos(size_t len) { preAlloc(len); return _bufFillPos; }