diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-12-21 05:01:45 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-12-21 05:01:45 +0000 |
commit | 2b51ff0dfcee66b2ed67ef3ce53eb3ef769cb585 (patch) | |
tree | e8f50c53751966585cd4490c722277179a5693da | |
parent | 9dd38b4d1f01fded878ef6b5488e48cccc5f4acd (diff) |
Deinline some non-trivial methods and do not provide assert.h in string.
37 files changed, 230 insertions, 190 deletions
diff --git a/document/src/vespa/document/base/globalid.cpp b/document/src/vespa/document/base/globalid.cpp index 2a0fe9f0e5d..7fa22d27971 100644 --- a/document/src/vespa/document/base/globalid.cpp +++ b/document/src/vespa/document/base/globalid.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/stllike/hash_set.hpp> +#include <cassert> namespace { diff --git a/document/src/vespa/document/bucket/bucketidfactory.cpp b/document/src/vespa/document/bucket/bucketidfactory.cpp index a0fa3085efd..afc5b283db2 100644 --- a/document/src/vespa/document/bucket/bucketidfactory.cpp +++ b/document/src/vespa/document/bucket/bucketidfactory.cpp @@ -4,7 +4,8 @@ #include <vespa/document/bucket/bucketid.h> #include <vespa/document/base/documentid.h> -#include <iostream> +#include <ostream> +#include <cassert> namespace document { diff --git a/fnet/src/vespa/fnet/channellookup.cpp b/fnet/src/vespa/fnet/channellookup.cpp index 1ba63a6019b..2e654d6a2a3 100644 --- a/fnet/src/vespa/fnet/channellookup.cpp +++ b/fnet/src/vespa/fnet/channellookup.cpp @@ -5,6 +5,7 @@ #include "controlpacket.h" #include "ipackethandler.h" #include <vespa/vespalib/stllike/hash_map.hpp> +#include <cassert> namespace fnet { diff --git a/searchcore/src/vespa/searchcore/proton/initializer/task_runner.h b/searchcore/src/vespa/searchcore/proton/initializer/task_runner.h index 2f68f0a24f7..4e89088b823 100644 --- a/searchcore/src/vespa/searchcore/proton/initializer/task_runner.h +++ b/searchcore/src/vespa/searchcore/proton/initializer/task_runner.h @@ -4,6 +4,7 @@ #include "initializer_task.h" #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/stllike/hash_set.h> +#include <cassert> namespace proton { diff --git a/searchlib/src/vespa/searchlib/diskindex/docidmapper.h b/searchlib/src/vespa/searchlib/diskindex/docidmapper.h index f150e8636a5..018fe35fb3a 100644 --- a/searchlib/src/vespa/searchlib/diskindex/docidmapper.h +++ b/searchlib/src/vespa/searchlib/diskindex/docidmapper.h @@ -3,14 +3,13 @@ #include <vespa/vespalib/util/array.h> #include <vespa/vespalib/stllike/string.h> +#include <cassert> -namespace search -{ +namespace search { class BitVector; -namespace diskindex -{ +namespace diskindex { typedef vespalib::Array<uint8_t> SelectorArray; @@ -21,21 +20,11 @@ public: const SelectorArray *_selector; // External ownership uint8_t _selectorId; - DocIdMapping(void); - - void - clear(void); - - void - setup(uint32_t docIdLimit); - - void - setup(uint32_t docIdLimit, - const SelectorArray *selector, - uint8_t selectorId); - - bool - readDocIdLimit(const vespalib::string &dir); + DocIdMapping(); + void clear(); + void setup(uint32_t docIdLimit); + void setup(uint32_t docIdLimit, const SelectorArray *selector, uint8_t selectorId); + bool readDocIdLimit(const vespalib::string &dir); }; @@ -47,17 +36,14 @@ public: uint32_t _selectorLimit; // Limit on output uint8_t _selectorId; - DocIdMapper(void) + DocIdMapper() : _selector(NULL), _docIdLimit(0u), _selectorLimit(0), _selectorId(0u) - { - } + { } - void - setup(const DocIdMapping &mapping) - { + void setup(const DocIdMapping &mapping) { _selector = (mapping._selector != NULL) ? &((*mapping._selector)[0]) : NULL; _docIdLimit = mapping._docIdLimit; @@ -67,15 +53,11 @@ public: _selectorId = mapping._selectorId; } - static uint32_t - noDocId(void) - { + static uint32_t noDocId() { return static_cast<uint32_t>(-1); } - uint32_t - mapDocId(uint32_t docId) const - { + uint32_t mapDocId(uint32_t docId) const { assert(docId < _docIdLimit); if (_selector != NULL && (docId >= _selectorLimit || _selector[docId] != _selectorId)) { diff --git a/searchlib/src/vespa/searchlib/fef/properties.cpp b/searchlib/src/vespa/searchlib/fef/properties.cpp index b501a445d91..a419eda0303 100644 --- a/searchlib/src/vespa/searchlib/fef/properties.cpp +++ b/searchlib/src/vespa/searchlib/fef/properties.cpp @@ -3,6 +3,7 @@ #include "properties.h" #include <vespa/vespalib/stllike/hash_map.hpp> #include <vespa/vespalib/stllike/hash_map_equal.hpp> +#include <cassert> namespace search { namespace fef { @@ -265,4 +266,4 @@ void Properties::swap(Properties & rhs) } // namespace fef } // namespace search -VESPALIB_HASH_MAP_INSTANTIATE(vespalib::string, search::fef::Property::Values);
\ No newline at end of file +VESPALIB_HASH_MAP_INSTANTIATE(vespalib::string, search::fef::Property::Values); diff --git a/searchlib/src/vespa/searchlib/query/tree/term.h b/searchlib/src/vespa/searchlib/query/tree/term.h index c13a586dd01..baa6656f66c 100644 --- a/searchlib/src/vespa/searchlib/query/tree/term.h +++ b/searchlib/src/vespa/searchlib/query/tree/term.h @@ -4,6 +4,7 @@ #include <vespa/vespalib/stllike/string.h> #include <vespa/searchlib/query/tree/node.h> #include <vespa/searchlib/query/weight.h> +#include <cassert> namespace search { namespace query { diff --git a/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp b/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp index 64affd5318e..204e5119397 100644 --- a/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/jsonwriter.cpp @@ -2,6 +2,7 @@ #include "jsonwriter.h" #include <vespa/vespalib/stllike/asciistream.h> #include <cmath> +#include <cassert> namespace vespalib { diff --git a/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp index 75d10f46262..d7f482fdf26 100644 --- a/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp +++ b/staging_vespalib/src/vespa/vespalib/util/xmlserializable.cpp @@ -1,9 +1,10 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/util/xmlserializable.hpp> -#include <vector> #include <vespa/vespalib/encoding/base64.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <vector> +#include <cassert> namespace vespalib { namespace xml { diff --git a/storage/src/vespa/storage/bucketdb/judyarray.h b/storage/src/vespa/storage/bucketdb/judyarray.h index 4ded2821af3..1c68e84084c 100644 --- a/storage/src/vespa/storage/bucketdb/judyarray.h +++ b/storage/src/vespa/storage/bucketdb/judyarray.h @@ -18,6 +18,7 @@ #include <vespa/vespalib/util/printable.h> #include <Judy.h> +#include <cassert> namespace storage { diff --git a/storage/src/vespa/storage/distributor/activecopy.cpp b/storage/src/vespa/storage/distributor/activecopy.cpp index 6ef783fb469..ecdab80e0c9 100644 --- a/storage/src/vespa/storage/distributor/activecopy.cpp +++ b/storage/src/vespa/storage/distributor/activecopy.cpp @@ -4,8 +4,9 @@ #include <vespa/storage/storageutil/utils.h> #include <vespa/vdslib/distribution/distribution.h> -#include <algorithm> #include <vespa/vespalib/stllike/asciistream.h> +#include <algorithm> +#include <cassert> namespace std { template<typename T> diff --git a/storage/src/vespa/storage/distributor/operations/idealstate/mergemetadata.h b/storage/src/vespa/storage/distributor/operations/idealstate/mergemetadata.h index dfefcabce73..8c1cb02bcda 100644 --- a/storage/src/vespa/storage/distributor/operations/idealstate/mergemetadata.h +++ b/storage/src/vespa/storage/distributor/operations/idealstate/mergemetadata.h @@ -3,6 +3,7 @@ #pragma once #include <vespa/storage/bucketdb/bucketcopy.h> +#include <cassert> namespace storage { namespace distributor { diff --git a/storageframework/src/vespa/storageframework/generic/clock/time.cpp b/storageframework/src/vespa/storageframework/generic/clock/time.cpp index db0c0b6697d..80f505fc00a 100644 --- a/storageframework/src/vespa/storageframework/generic/clock/time.cpp +++ b/storageframework/src/vespa/storageframework/generic/clock/time.cpp @@ -4,6 +4,7 @@ #include "clock.h" #include <iomanip> #include <vector> +#include <cassert> namespace storage { namespace framework { diff --git a/storageframework/src/vespa/storageframework/generic/status/xmlstatusreporter.cpp b/storageframework/src/vespa/storageframework/generic/status/xmlstatusreporter.cpp index 04ddb25bdc5..d768d71f247 100644 --- a/storageframework/src/vespa/storageframework/generic/status/xmlstatusreporter.cpp +++ b/storageframework/src/vespa/storageframework/generic/status/xmlstatusreporter.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "xmlstatusreporter.h" +#include <cassert> namespace storage { namespace framework { diff --git a/vespalib/src/vespa/vespalib/component/version.cpp b/vespalib/src/vespa/vespalib/component/version.cpp index ea8f3fdbde9..8e385b74eae 100644 --- a/vespalib/src/vespa/vespalib/component/version.cpp +++ b/vespalib/src/vespa/vespalib/component/version.cpp @@ -1,17 +1,26 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> #include "version.h" -#include <vespa/vespalib/util/exception.h> #include <vespa/vespalib/util/exceptions.h> -#include <ctype.h> #include <vespa/vespalib/stllike/asciistream.h> - -using vespalib::stringref; +#include <cctype> +#include <climits> namespace vespalib { +Version::Version(int major, int minor, int micro, const string & qualifier) + : _major(major), + _minor(minor), + _micro(micro), + _qualifier(qualifier), + _stringValue() +{ + initialize(); +} + +Version::~Version() { } + void Version::initialize() { diff --git a/vespalib/src/vespa/vespalib/component/version.h b/vespalib/src/vespa/vespalib/component/version.h index e637e46ff90..58c680ce8f1 100644 --- a/vespalib/src/vespa/vespalib/component/version.h +++ b/vespalib/src/vespa/vespalib/component/version.h @@ -59,15 +59,8 @@ public: * the qualifier string contains non-word/digit-characters */ - Version(int major = 0, int minor = 0, int micro = 0, const string & qualifier = "") - : _major(major), - _minor(minor), - _micro(micro), - _qualifier(qualifier), - _stringValue() - { - initialize(); - } + Version(int major = 0, int minor = 0, int micro = 0, const string & qualifier = ""); + ~Version(); /** * @brief Creates a version identifier from the specified string. diff --git a/vespalib/src/vespa/vespalib/component/versionspecification.cpp b/vespalib/src/vespa/vespalib/component/versionspecification.cpp index af200b21caa..e54550a7fc8 100644 --- a/vespalib/src/vespa/vespalib/component/versionspecification.cpp +++ b/vespalib/src/vespa/vespalib/component/versionspecification.cpp @@ -1,16 +1,27 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> #include "version.h" #include "versionspecification.h" -#include <vespa/vespalib/util/exception.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/text/stringtokenizer.h> #include <vespa/vespalib/stllike/asciistream.h> -#include <ctype.h> +#include <cctype> +#include <climits> namespace vespalib { +VersionSpecification::VersionSpecification(int major, int minor, int micro, const string & qualifier) + : _major(major), + _minor(minor), + _micro(micro), + _qualifier(qualifier), + _stringValue() +{ + initialize(); +} + +VersionSpecification::~VersionSpecification() { } + void VersionSpecification::initialize() { diff --git a/vespalib/src/vespa/vespalib/component/versionspecification.h b/vespalib/src/vespa/vespalib/component/versionspecification.h index f19af4c429f..547b140c701 100644 --- a/vespalib/src/vespa/vespalib/component/versionspecification.h +++ b/vespalib/src/vespa/vespalib/component/versionspecification.h @@ -65,18 +65,9 @@ public: * an earlier component is not specified but a later one is */ - VersionSpecification(int major = UNSPECIFIED, - int minor = UNSPECIFIED, - int micro = UNSPECIFIED, - const string & qualifier = "") - : _major(major), - _minor(minor), - _micro(micro), - _qualifier(qualifier), - _stringValue() - { - initialize(); - } + VersionSpecification(int major = UNSPECIFIED, int minor = UNSPECIFIED, + int micro = UNSPECIFIED, const string & qualifier = ""); + ~VersionSpecification(); /** * @brief Creates a version specification from the specified string. diff --git a/vespalib/src/vespa/vespalib/component/vtag.cpp b/vespalib/src/vespa/vespalib/component/vtag.cpp index c6619c29f1c..f62c5dcda55 100644 --- a/vespalib/src/vespa/vespalib/component/vtag.cpp +++ b/vespalib/src/vespa/vespalib/component/vtag.cpp @@ -1,5 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <stdio.h> +#include <cstdio> #include "vtag.h" #ifndef V_TAG diff --git a/vespalib/src/vespa/vespalib/eval/basic_nodes.h b/vespalib/src/vespa/vespalib/eval/basic_nodes.h index aadf0cbf25a..2887856a66d 100644 --- a/vespalib/src/vespa/vespalib/eval/basic_nodes.h +++ b/vespalib/src/vespa/vespalib/eval/basic_nodes.h @@ -2,12 +2,13 @@ #pragma once -#include <memory> -#include <map> -#include <vector> #include <vespa/vespalib/stllike/string.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/string_hash.h> +#include <memory> +#include <map> +#include <vector> +#include <cassert> namespace vespalib { namespace eval { diff --git a/vespalib/src/vespa/vespalib/net/socket_address.cpp b/vespalib/src/vespa/vespalib/net/socket_address.cpp index 76ae01418c6..d6cb5a3582b 100644 --- a/vespalib/src/vespa/vespalib/net/socket_address.cpp +++ b/vespalib/src/vespa/vespalib/net/socket_address.cpp @@ -7,6 +7,7 @@ #include <sys/un.h> #include <arpa/inet.h> #include <netdb.h> +#include <cassert> namespace vespalib { diff --git a/vespalib/src/vespa/vespalib/objects/nbostream.hpp b/vespalib/src/vespa/vespalib/objects/nbostream.hpp index 767c485550c..9de31b10916 100644 --- a/vespalib/src/vespa/vespalib/objects/nbostream.hpp +++ b/vespalib/src/vespa/vespalib/objects/nbostream.hpp @@ -2,6 +2,7 @@ #pragma once #include "nbostream.h" +#include <cassert> namespace vespalib { diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp index f49e1a29581..bcd4cd1dcb5 100644 --- a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp +++ b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp @@ -1,6 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/util/stringfmt.h> #include <algorithm> @@ -8,6 +7,7 @@ #include <stdexcept> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/util/memory.h> +#include <vespa/fastos/file.h> namespace vespalib { @@ -28,6 +28,20 @@ namespace { std::vector<string> autoPrecisions = getPrecisions('g'); } +asciistream & +asciistream::operator << (Precision v) { + assert(v.getPrecision() <= VESPALIB_ASCIISTREAM_MAX_PRECISION); + _precision = v.getPrecision(); + return *this; +} + +asciistream & +asciistream::operator >> (Precision v) { + assert(v.getPrecision() <= VESPALIB_ASCIISTREAM_MAX_PRECISION); + _precision = v.getPrecision(); + return *this; +} + asciistream::asciistream() : _rPos(0), _wbuf(), @@ -38,8 +52,7 @@ asciistream::asciistream() : _width(0), _fill(' '), _precision(6) -{ -} +{ } asciistream::asciistream(const stringref & buf) : _rPos(0), diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.h b/vespalib/src/vespa/vespalib/stllike/asciistream.h index 64d1cbb7fcc..14d0b1b35b3 100644 --- a/vespalib/src/vespa/vespalib/stllike/asciistream.h +++ b/vespalib/src/vespa/vespalib/stllike/asciistream.h @@ -35,6 +35,8 @@ public: ~asciistream(); asciistream(const asciistream & rhs); asciistream & operator = (const asciistream & rhs); + asciistream(asciistream &&) = default; + asciistream & operator = (asciistream &&) = default; void swap(asciistream & rhs); asciistream & operator << (bool v) { if (v) { *this << '1'; } else { *this << '0'; } return *this; } asciistream & operator << (char v) { doFill(1); write(&v, 1); return *this; } @@ -139,8 +141,8 @@ public: asciistream & operator >> (Width v) { _width = v.getWidth(); return *this; } asciistream & operator << (Fill v) { _fill = v.getFill(); return *this; } asciistream & operator >> (Fill v) { _fill = v.getFill(); return *this; } - asciistream & operator << (Precision v) { assert(v.getPrecision() <= VESPALIB_ASCIISTREAM_MAX_PRECISION); _precision = v.getPrecision(); return *this; } - asciistream & operator >> (Precision v) { assert(v.getPrecision() <= VESPALIB_ASCIISTREAM_MAX_PRECISION); _precision = v.getPrecision(); return *this; } + asciistream & operator << (Precision v); + asciistream & operator >> (Precision v); void eatWhite(); static asciistream createFromFile(const vespalib::stringref & fileName); static asciistream createFromDevice(const vespalib::stringref & fileName); diff --git a/vespalib/src/vespa/vespalib/stllike/string.cpp b/vespalib/src/vespa/vespalib/stllike/string.cpp index e8a6552f531..be09f00d4b0 100644 --- a/vespalib/src/vespa/vespalib/stllike/string.cpp +++ b/vespalib/src/vespa/vespalib/stllike/string.cpp @@ -1,6 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> #include <vespa/vespalib/stllike/string.hpp> #include <ostream> #include <istream> @@ -9,6 +8,43 @@ namespace vespalib { const stringref::size_type stringref::npos; +stringref::size_type +stringref::rfind(const char * s, size_type e) const { + size_type n = strlen(s); + if (n <= size()) { + size_type sz = std::min(size()-n, e); + const char *b = begin(); + do { + if (s[0] == b[sz]) { + bool found(true); + for(size_t i(1); found && (i < n); i++) { + found = s[i] == b[sz+i]; + } + if (found) { + return sz; + } + } + } while (sz-- > 0); + } + return npos; +} + +stringref::size_type +stringref::find(const stringref & s, size_type start) const { + const char *buf = begin()+start; + const char *e = end() - s.size(); + while (buf <= e) { + size_t i(0); + for (; (i < s.size()) && (buf[i] == s[i]); i++); + if (i == s.size()) { + return buf - begin(); + } else { + buf++; + } + } + return npos; +} + std::ostream & operator << (std::ostream & os, const stringref & v) { return os.write(v.c_str(), v.size()); diff --git a/vespalib/src/vespa/vespalib/stllike/string.h b/vespalib/src/vespa/vespalib/stllike/string.h index 79dd95ebf37..bb562ac3a00 100644 --- a/vespalib/src/vespa/vespalib/stllike/string.h +++ b/vespalib/src/vespa/vespalib/stllike/string.h @@ -1,11 +1,10 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <assert.h> #include <string> -#include <string.h> -#include <stdint.h> -#include <stdlib.h> +#include <cstring> +#include <cstdint> +#include <cstdlib> #include <vespa/vespalib/util/alloc.h> namespace vespalib { @@ -75,20 +74,7 @@ public: * @return index from the start of the string at which the character * was found, or npos if the character could not be located */ - size_type find(const stringref & s, size_type start=0) const { - const char *buf = begin()+start; - const char *e = end() - s.size(); - while (buf <= e) { - size_t i(0); - for (; (i < s.size()) && (buf[i] == s[i]); i++); - if (i == s.size()) { - return buf - begin(); - } else { - buf++; - } - } - return npos; - } + size_type find(const stringref & s, size_type start=0) const; /** * Find the first occurrence of a character, searching from @c start * @@ -132,25 +118,7 @@ public: * @return index from the start of the string at which the substring * was found, or npos if the substring could not be located */ - size_type rfind(const char * s, size_type e=npos) const { - size_type n = strlen(s); - if (n <= size()) { - size_type sz = std::min(size()-n, e); - const char *b = begin(); - do { - if (s[0] == b[sz]) { - bool found(true); - for(size_t i(1); found && (i < n); i++) { - found = s[i] == b[sz+i]; - } - if (found) { - return sz; - } - } - } while (sz-- > 0); - } - return npos; - } + size_type rfind(const char * s, size_type e=npos) const; int compare(const stringref & s) const { return compare(s.c_str(), s.size()); } int compare(const char *s, size_type sz) const { int diff(memcmp(_s, s, std::min(sz, size()))); @@ -282,25 +250,7 @@ public: * @return index from the start of the string at which the substring * was found, or npos if the substring could not be located */ - size_type rfind(const char * s, size_type e=npos) const { - size_type n = strlen(s); - if (n <= size()) { - size_type sz = std::min(size()-n, e); - const char *b = buffer(); - do { - if (s[0] == b[sz]) { - bool found(true); - for(size_t i(1); found && (i < n); i++) { - found = s[i] == b[sz+i]; - } - if (found) { - return sz; - } - } - } while (sz-- > 0); - } - return npos; - } + size_type rfind(const char * s, size_type e=npos) const; /** * Find the last occurrence of a character, starting at e and @@ -369,17 +319,7 @@ public: return (found != NULL) ? (found - buffer()) : (size_type)npos; } small_string & assign(const char * s) { return assign(s, strlen(s)); } - small_string & assign(const void * s, size_type sz) { - if (__builtin_expect(capacity() >= sz, true)) { - char *buf = buffer(); - memmove(buf, s, sz); - buf[sz] = '\0'; - _sz = sz; - } else { - assign_slower(s, sz); - } - return *this; - } + small_string & assign(const void * s, size_type sz); small_string & assign(const stringref &s, size_type pos, size_type sz) { return assign(s.c_str() + pos, sz); } @@ -478,10 +418,7 @@ public: * @param p2 position in s where replacement content starts * @param n2 how many new characters to use **/ - small_string& replace (size_t p1, size_t n1, const small_string& s, size_t p2, size_t n2 ) { - assert(s.size() >= (p2+n2)); - return replace(p1, n1, s.c_str()+p2, n2); - } + small_string& replace (size_t p1, size_t n1, const small_string& s, size_t p2, size_t n2); /** * at position p1, replace n1 characters with @@ -492,18 +429,7 @@ public: * @param s pointer to new content * @param n2 how many new characters to use **/ - small_string& replace (size_t p1, size_t n1, const char *s, size_t n2 ) { - assert (size() >= (p1 + n1)); - const size_t newSz = n2 + size() - n1; - if (n1 < n2) { - reserve(newSz); - } - size_t rest = size()-(p1+n1); - memmove(buffer()+p1+n2, buffer()+p1+n1, rest); - memcpy(buffer()+p1, s, n2); - _resize(newSz); - return *this; - } + small_string& replace (size_t p1, size_t n1, const char *s, size_t n2); /** * at position p1, replace n1 characters with the contents of s @@ -576,14 +502,11 @@ public: /** * Will extend the string within its current buffer. Assumes memory is already initialized. * Can not extend beyond capacity. - * Not this is non-STL. + * Note this is non-STL. * * @param newSz new size of string. */ - void append_from_reserved(size_type sz) { - assert(size() + sz <= capacity()); - _resize(size() + sz); - } + void append_from_reserved(size_type sz); /** * Ensure string has at least newCapacity characters of available @@ -598,17 +521,10 @@ public: private: void assign_slower(const void * s, size_type sz) __attribute((noinline)); void init_slower(const void *s) __attribute((noinline)); + void _reserveBytes(size_type newBufferSize); void reserveBytes(size_type newBufferSize) { if (newBufferSize > _bufferSize) { - if (isAllocated()) { - _buf = (char *) realloc(_buf, newBufferSize); - } else { - char *tmp = (char *) malloc(newBufferSize); - memcpy(tmp, _stack, _sz); - tmp[_sz] = '\0'; - _buf = tmp; - } - _bufferSize = newBufferSize; + _reserveBytes(newBufferSize); } } typedef uint32_t isize_type; diff --git a/vespalib/src/vespa/vespalib/stllike/string.hpp b/vespalib/src/vespa/vespalib/stllike/string.hpp index 2c5548e30cd..94d5475740b 100644 --- a/vespalib/src/vespa/vespalib/stllike/string.hpp +++ b/vespalib/src/vespa/vespalib/stllike/string.hpp @@ -1,8 +1,88 @@ #include "string.h" +#include <cassert> namespace vespalib { template <uint32_t StackSize> +void +small_string<StackSize>::append_from_reserved(size_type sz) { + assert(size() + sz <= capacity()); + _resize(size() + sz); +} + +template <uint32_t StackSize> +void +small_string<StackSize>::_reserveBytes(size_type newBufferSize) { + if (isAllocated()) { + _buf = (char *) realloc(_buf, newBufferSize); + } else { + char *tmp = (char *) malloc(newBufferSize); + memcpy(tmp, _stack, _sz); + tmp[_sz] = '\0'; + _buf = tmp; + } + _bufferSize = newBufferSize; +} + +template <uint32_t StackSize> +small_string<StackSize>& +small_string<StackSize>::replace (size_t p1, size_t n1, const small_string& s, size_t p2, size_t n2 ) { + assert(s.size() >= (p2+n2)); + return replace(p1, n1, s.c_str()+p2, n2); +} + +template <uint32_t StackSize> +small_string<StackSize>& +small_string<StackSize>::replace (size_t p1, size_t n1, const char *s, size_t n2 ) { + assert (size() >= (p1 + n1)); + const size_t newSz = n2 + size() - n1; + if (n1 < n2) { + reserve(newSz); + } + size_t rest = size()-(p1+n1); + memmove(buffer()+p1+n2, buffer()+p1+n1, rest); + memcpy(buffer()+p1, s, n2); + _resize(newSz); + return *this; +} + +template <uint32_t StackSize> +typename small_string<StackSize>::size_type +small_string<StackSize>::rfind(const char * s, size_type e) const { + size_type n = strlen(s); + if (n <= size()) { + size_type sz = std::min(size()-n, e); + const char *b = buffer(); + do { + if (s[0] == b[sz]) { + bool found(true); + for(size_t i(1); found && (i < n); i++) { + found = s[i] == b[sz+i]; + } + if (found) { + return sz; + } + } + } while (sz-- > 0); + } + return npos; +} + +template <uint32_t StackSize> +small_string<StackSize> & +small_string<StackSize>::assign(const void * s, size_type sz) { + if (__builtin_expect(capacity() >= sz, true)) { + char *buf = buffer(); + memmove(buf, s, sz); + buf[sz] = '\0'; + _sz = sz; + } else { + assign_slower(s, sz); + } + return *this; +} + +template <uint32_t StackSize> void small_string<StackSize>::assign_slower(const void * s, size_type sz) { reset(); diff --git a/vespalib/src/vespa/vespalib/tensor/dense/dense_tensor_builder.cpp b/vespalib/src/vespa/vespalib/tensor/dense/dense_tensor_builder.cpp index db2a4ffaac8..872be49f9b4 100644 --- a/vespalib/src/vespa/vespalib/tensor/dense/dense_tensor_builder.cpp +++ b/vespalib/src/vespa/vespalib/tensor/dense/dense_tensor_builder.cpp @@ -2,6 +2,7 @@ #include "dense_tensor_builder.h" #include <vespa/vespalib/util/exceptions.h> +#include <cassert> using vespalib::IllegalArgumentException; using vespalib::make_string; diff --git a/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_padder.h b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_padder.h index abf73d5458e..89372004a09 100644 --- a/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_padder.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_padder.h @@ -4,6 +4,7 @@ #include "sparse_tensor_address_builder.h" #include "sparse_tensor_address_decoder.h" +#include <cassert> namespace vespalib { namespace tensor { diff --git a/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_reducer.h b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_reducer.h index d92d83236c9..d1698681a55 100644 --- a/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_reducer.h +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_address_reducer.h @@ -5,6 +5,7 @@ #include "sparse_tensor_address_builder.h" #include <vespa/vespalib/tensor/types.h> #include "sparse_tensor_address_decoder.h" +#include <cassert> namespace vespalib { namespace eval { class ValueType; } diff --git a/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_builder.cpp b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_builder.cpp index beddc79cc9a..afab04fef6c 100644 --- a/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_builder.cpp +++ b/vespalib/src/vespa/vespalib/tensor/sparse/sparse_tensor_builder.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "sparse_tensor_builder.h" +#include <cassert> namespace vespalib { namespace tensor { diff --git a/vespalib/src/vespa/vespalib/text/lowercase.cpp b/vespalib/src/vespa/vespalib/text/lowercase.cpp index 1e320c657b3..8320fe2e53a 100644 --- a/vespalib/src/vespa/vespalib/text/lowercase.cpp +++ b/vespalib/src/vespa/vespalib/text/lowercase.cpp @@ -1,7 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> -#include <assert.h> #include "lowercase.h" #include <vespa/vespalib/text/utf8.h> diff --git a/vespalib/src/vespa/vespalib/text/stringtokenizer.cpp b/vespalib/src/vespa/vespalib/text/stringtokenizer.cpp index 8ce49bec213..d1e9ef9e9ca 100644 --- a/vespalib/src/vespa/vespalib/text/stringtokenizer.cpp +++ b/vespalib/src/vespa/vespalib/text/stringtokenizer.cpp @@ -1,8 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/fastos/fastos.h> #include "stringtokenizer.h" -#include <set> namespace { diff --git a/vespalib/src/vespa/vespalib/text/utf8.cpp b/vespalib/src/vespa/vespalib/text/utf8.cpp index 6fba50825af..f970ec4a725 100644 --- a/vespalib/src/vespa/vespalib/text/utf8.cpp +++ b/vespalib/src/vespa/vespalib/text/utf8.cpp @@ -3,7 +3,7 @@ #include "utf8.h" #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/exceptions.h> -#include <assert.h> +#include <cassert> #include <vespa/log/log.h> LOG_SETUP(".vespalib.utf8"); diff --git a/vespalib/src/vespa/vespalib/trace/tracenode.cpp b/vespalib/src/vespa/vespalib/trace/tracenode.cpp index 39c138bb875..5cd3a18f19a 100644 --- a/vespalib/src/vespa/vespalib/trace/tracenode.cpp +++ b/vespalib/src/vespa/vespalib/trace/tracenode.cpp @@ -2,9 +2,8 @@ #include <vespa/vespalib/trace/tracenode.h> #include <vespa/vespalib/trace/tracevisitor.h> - #include <algorithm> -#include <vespa/fastos/fastos.h> + #include <vespa/log/log.h> LOG_SETUP(".tracenode"); @@ -48,9 +47,7 @@ TraceNode::TraceNode() : _note(""), _children(), _timestamp(0) -{ - // empty -} +{ } TraceNode::TraceNode(const TraceNode &rhs) : _parent(NULL), @@ -72,9 +69,7 @@ TraceNode::TraceNode(const string ¬e, int64_t timestamp) : _note(note), _children(), _timestamp(timestamp) -{ - // empty -} +{ } TraceNode::TraceNode(int64_t timestamp) : _parent(NULL), @@ -83,9 +78,7 @@ TraceNode::TraceNode(int64_t timestamp) : _note(""), _children(), _timestamp(timestamp) -{ - // empty -} +{ } TraceNode & TraceNode::swap(TraceNode &other) diff --git a/vespalib/src/vespa/vespalib/trace/tracevisitor.h b/vespalib/src/vespa/vespalib/trace/tracevisitor.h index ceed30a7fd0..6c61073884b 100644 --- a/vespalib/src/vespa/vespalib/trace/tracevisitor.h +++ b/vespalib/src/vespa/vespalib/trace/tracevisitor.h @@ -1,9 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <vector> -#include <vespa/vespalib/stllike/string.h> - namespace vespalib { class TraceNode; diff --git a/vespalib/src/vespa/vespalib/util/stringfmt.cpp b/vespalib/src/vespa/vespalib/util/stringfmt.cpp index ca6d2d5af17..3a82194bb41 100644 --- a/vespalib/src/vespa/vespalib/util/stringfmt.cpp +++ b/vespalib/src/vespa/vespalib/util/stringfmt.cpp @@ -2,6 +2,7 @@ #include "stringfmt.h" #include "vstringfmt.h" +#include <cassert> namespace vespalib { |