diff options
author | Tyler Brock <tyler.brock@gmail.com> | 2015-02-06 14:29:45 -0500 |
---|---|---|
committer | Tyler Brock <tyler.brock@gmail.com> | 2015-02-06 16:37:35 -0500 |
commit | aa9980b8c02de71c6918fba4aba9f22dd10eed01 (patch) | |
tree | 3ade9078069c7e1317a8b31c2e1fc427977d7abe /src/mongo/base | |
parent | 3a7675bb6fa110a10be307db3201bfb348cf41cf (diff) | |
download | mongo-aa9980b8c02de71c6918fba4aba9f22dd10eed01.tar.gz |
SERVER-16940 Change pass-by-const-ref of StringData to pass-by-value
Diffstat (limited to 'src/mongo/base')
-rw-r--r-- | src/mongo/base/generate_error_codes.py | 4 | ||||
-rw-r--r-- | src/mongo/base/parse_number.cpp | 10 | ||||
-rw-r--r-- | src/mongo/base/parse_number.h | 4 | ||||
-rw-r--r-- | src/mongo/base/status.cpp | 4 | ||||
-rw-r--r-- | src/mongo/base/status.h | 4 | ||||
-rw-r--r-- | src/mongo/base/string_data-inl.h | 10 | ||||
-rw-r--r-- | src/mongo/base/string_data.cpp | 10 | ||||
-rw-r--r-- | src/mongo/base/string_data.h | 26 |
8 files changed, 36 insertions, 36 deletions
diff --git a/src/mongo/base/generate_error_codes.py b/src/mongo/base/generate_error_codes.py index 693f6b966e6..ad93656a7d1 100644 --- a/src/mongo/base/generate_error_codes.py +++ b/src/mongo/base/generate_error_codes.py @@ -209,7 +209,7 @@ namespace mongo { * * NOTE: Also returns UnknownError for the string "UnknownError". */ - static Error fromString(const StringData& name); + static Error fromString(StringData name); /** * Casts an integer "code" to an Error. Unrecognized codes are preserved, meaning @@ -268,7 +268,7 @@ namespace mongo { } } - ErrorCodes::Error ErrorCodes::fromString(const StringData& name) { + ErrorCodes::Error ErrorCodes::fromString(StringData name) { %(string_to_symbol_cases)s; return UnknownError; } diff --git a/src/mongo/base/parse_number.cpp b/src/mongo/base/parse_number.cpp index e861ac363b9..b384fab9494 100644 --- a/src/mongo/base/parse_number.cpp +++ b/src/mongo/base/parse_number.cpp @@ -59,7 +59,7 @@ namespace mongo { * substring with any sign characters stripped away. "*isNegative" is set to true if the * number is negative, and false otherwise. */ - static inline StringData _extractSign(const StringData& stringValue, bool* isNegative) { + static inline StringData _extractSign(StringData stringValue, bool* isNegative) { if (stringValue.empty()) { *isNegative = false; return stringValue; @@ -96,7 +96,7 @@ namespace mongo { * "0x" or "0X" prefix, if present. */ static inline StringData _extractBase( - const StringData& stringValue, int inputBase, int* outputBase) { + StringData stringValue, int inputBase, int* outputBase) { const StringData hexPrefixLower("0x", StringData::LiteralTag()); const StringData hexPrefixUpper("0X", StringData::LiteralTag()); @@ -125,7 +125,7 @@ namespace mongo { template <typename NumberType> Status parseNumberFromStringWithBase( - const StringData& stringValue, int base, NumberType* result) { + StringData stringValue, int base, NumberType* result) { typedef ::std::numeric_limits<NumberType> limits; @@ -193,7 +193,7 @@ namespace mongo { // Definition of the various supported implementations of parseNumberFromStringWithBase. #define DEFINE_PARSE_NUMBER_FROM_STRING_WITH_BASE(NUMBER_TYPE) \ - template MONGO_COMPILER_API_EXPORT Status parseNumberFromStringWithBase<NUMBER_TYPE>(const StringData&, int, NUMBER_TYPE*); + template MONGO_COMPILER_API_EXPORT Status parseNumberFromStringWithBase<NUMBER_TYPE>(StringData, int, NUMBER_TYPE*); DEFINE_PARSE_NUMBER_FROM_STRING_WITH_BASE(long) DEFINE_PARSE_NUMBER_FROM_STRING_WITH_BASE(long long) @@ -226,7 +226,7 @@ namespace { #endif // defined(_WIN32) template <> - Status parseNumberFromStringWithBase<double>(const StringData& stringValue, + Status parseNumberFromStringWithBase<double>(StringData stringValue, int base, double* result) { if (base != 0) { diff --git a/src/mongo/base/parse_number.h b/src/mongo/base/parse_number.h index f5729eac840..900a0963e55 100644 --- a/src/mongo/base/parse_number.h +++ b/src/mongo/base/parse_number.h @@ -55,10 +55,10 @@ namespace mongo { * See parse_number.cpp for the available instantiations, and add any new instantiations there. */ template <typename NumberType> - MONGO_CLIENT_API Status parseNumberFromStringWithBase(const StringData& stringValue, int base, NumberType* result); + MONGO_CLIENT_API Status parseNumberFromStringWithBase(StringData stringValue, int base, NumberType* result); template <typename NumberType> - static Status parseNumberFromString(const StringData& stringValue, NumberType* result) { + static Status parseNumberFromString(StringData stringValue, NumberType* result) { return parseNumberFromStringWithBase(stringValue, 0, result); } diff --git a/src/mongo/base/status.cpp b/src/mongo/base/status.cpp index 81e7e6d0eb8..9e88e879d75 100644 --- a/src/mongo/base/status.cpp +++ b/src/mongo/base/status.cpp @@ -32,11 +32,11 @@ namespace mongo { - Status::ErrorInfo::ErrorInfo(ErrorCodes::Error aCode, const StringData& aReason, int aLocation) + Status::ErrorInfo::ErrorInfo(ErrorCodes::Error aCode, StringData aReason, int aLocation) : code(aCode), reason(aReason.toString()), location(aLocation) { } - Status::ErrorInfo* Status::ErrorInfo::create(ErrorCodes::Error c, const StringData& r, int l) { + Status::ErrorInfo* Status::ErrorInfo::create(ErrorCodes::Error c, StringData r, int l) { const bool needRep = ((c != ErrorCodes::OK) || !r.empty() || (l != 0)); diff --git a/src/mongo/base/status.h b/src/mongo/base/status.h index d6062ceb0ee..2b32ecc1a89 100644 --- a/src/mongo/base/status.h +++ b/src/mongo/base/status.h @@ -130,9 +130,9 @@ namespace mongo { const int location; // unique location of the triggering line in the code static ErrorInfo* create(ErrorCodes::Error code, - const StringData& reason, int location); + StringData reason, int location); - ErrorInfo(ErrorCodes::Error code, const StringData& reason, int location); + ErrorInfo(ErrorCodes::Error code, StringData reason, int location); }; ErrorInfo* _error; diff --git a/src/mongo/base/string_data-inl.h b/src/mongo/base/string_data-inl.h index 7d1d726d8a4..4c8a0bdc924 100644 --- a/src/mongo/base/string_data-inl.h +++ b/src/mongo/base/string_data-inl.h @@ -33,7 +33,7 @@ namespace mongo { - inline int StringData::compare(const StringData& other) const { + inline int StringData::compare(StringData other) const { int res = memcmp(_data, other._data, std::min(_size, other._size)); if (res != 0) { return res > 0 ? 1 : -1; @@ -46,7 +46,7 @@ namespace mongo { } } - inline bool StringData::equalCaseInsensitive( const StringData& other ) const { + inline bool StringData::equalCaseInsensitive( StringData other ) const { if ( other.size() != size() ) return false; @@ -79,7 +79,7 @@ namespace mongo { return static_cast<size_t>( static_cast<const char*>(x) - _data ); } - inline size_t StringData::find( const StringData& needle ) const { + inline size_t StringData::find( StringData needle ) const { size_t mx = size(); size_t needleSize = needle.size(); @@ -121,12 +121,12 @@ namespace mongo { return StringData( _data + pos, n ); } - inline bool StringData::startsWith( const StringData& prefix ) const { + inline bool StringData::startsWith( StringData prefix ) const { // TODO: Investigate an optimized implementation. return substr(0, prefix.size()) == prefix; } - inline bool StringData::endsWith( const StringData& suffix ) const { + inline bool StringData::endsWith( StringData suffix ) const { // TODO: Investigate an optimized implementation. const size_t thisSize = size(); const size_t suffixSize = suffix.size(); diff --git a/src/mongo/base/string_data.cpp b/src/mongo/base/string_data.cpp index e6b464c5901..2774f4deb4e 100644 --- a/src/mongo/base/string_data.cpp +++ b/src/mongo/base/string_data.cpp @@ -35,17 +35,17 @@ namespace mongo { namespace { template <int SizeofSizeT> - size_t murmur3(const StringData& str); + size_t murmur3(StringData str); template <> - size_t murmur3<4>(const StringData& str) { + size_t murmur3<4>(StringData str) { uint32_t hash; MurmurHash3_x86_32(str.rawData(), str.size(), 0, &hash); return hash; } template <> - size_t murmur3<8>(const StringData& str) { + size_t murmur3<8>(StringData str) { uint64_t hash[2]; MurmurHash3_x64_128(str.rawData(), str.size(), 0, hash); return static_cast<size_t>(hash[0]); @@ -53,11 +53,11 @@ namespace mongo { } // namespace - std::ostream& operator<<(std::ostream& stream, const StringData& value) { + std::ostream& operator<<(std::ostream& stream, StringData value) { return stream.write(value.rawData(), value.size()); } - size_t StringData::Hasher::operator() (const StringData& str) const { + size_t StringData::Hasher::operator() (StringData str) const { return murmur3<sizeof(size_t)>(str); } diff --git a/src/mongo/base/string_data.h b/src/mongo/base/string_data.h index a1327fefe90..e70d27fc975 100644 --- a/src/mongo/base/string_data.h +++ b/src/mongo/base/string_data.h @@ -89,14 +89,14 @@ namespace mongo { * Returns -1, 0, or 1 if 'this' is less, equal, or greater than 'other' in * lexicographical order. */ - int compare(const StringData& other) const; + int compare(StringData other) const; /** * note: this uses tolower, and therefore does not handle * come languages correctly. * should be use sparingly */ - bool equalCaseInsensitive( const StringData& other ) const; + bool equalCaseInsensitive( StringData other ) const; void copyTo( char* dest, bool includeEndingNull ) const; @@ -107,18 +107,18 @@ namespace mongo { // size_t find( char c , size_t fromPos = 0 ) const; - size_t find( const StringData& needle ) const; + size_t find( StringData needle ) const; size_t rfind( char c, size_t fromPos = std::string::npos ) const; /** * Returns true if 'prefix' is a substring of this instance, anchored at position 0. */ - bool startsWith( const StringData& prefix ) const; + bool startsWith( StringData prefix ) const; /** * Returns true if 'suffix' is a substring of this instance, anchored at the end. */ - bool endsWith( const StringData& suffix ) const; + bool endsWith( StringData suffix ) const; // // accessors @@ -142,7 +142,7 @@ namespace mongo { * to be consistent across versions. */ struct Hasher { - size_t operator() (const StringData& str) const; + size_t operator() (StringData str) const; }; // @@ -159,31 +159,31 @@ namespace mongo { size_t _size; // 'size' does not include the null terminator }; - inline bool operator==(const StringData& lhs, const StringData& rhs) { + inline bool operator==(StringData lhs, StringData rhs) { return (lhs.size() == rhs.size()) && (lhs.compare(rhs) == 0); } - inline bool operator!=(const StringData& lhs, const StringData& rhs) { + inline bool operator!=(StringData lhs, StringData rhs) { return !(lhs == rhs); } - inline bool operator<(const StringData& lhs, const StringData& rhs) { + inline bool operator<(StringData lhs, StringData rhs) { return lhs.compare(rhs) < 0 ; } - inline bool operator<=(const StringData& lhs, const StringData& rhs) { + inline bool operator<=(StringData lhs, StringData rhs) { return lhs.compare(rhs) <= 0; } - inline bool operator>(const StringData& lhs, const StringData& rhs) { + inline bool operator>(StringData lhs, StringData rhs) { return lhs.compare(rhs) > 0; } - inline bool operator>=(const StringData& lhs, const StringData& rhs) { + inline bool operator>=(StringData lhs, StringData rhs) { return lhs.compare(rhs) >= 0; } - std::ostream& operator<<(std::ostream& stream, const StringData& value); + std::ostream& operator<<(std::ostream& stream, StringData value); } // namespace mongo |