From 55579edd61d95b86c9a4ea40bf1df928f51f4fc3 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 23 May 2023 12:40:20 +0000 Subject: Inline small frequently called methods --- searchlib/src/vespa/searchlib/util/rawbuf.cpp | 60 --------------------------- searchlib/src/vespa/searchlib/util/rawbuf.h | 39 +++++++++++++---- 2 files changed, 31 insertions(+), 68 deletions(-) (limited to 'searchlib') 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 #include -#include #include namespace search { -RawBuf::RawBuf(size_t size) - : _bufStart(nullptr), - _bufEnd(nullptr), - _bufFillPos(nullptr), - _bufDrainPos(nullptr) -{ - if (size > 0) { - _bufStart = static_cast(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 -#include +#include +#include +#include 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(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; } -- cgit v1.2.3