summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2014-11-17 15:20:59 -0500
committerAndrew Morrow <acm@mongodb.com>2014-11-18 12:13:01 -0500
commitadb1e5f25f3f5eacbbed382426542623b67632e5 (patch)
treeff22ce20fad07fbe2b2afa459cfc31ee6bb152d3 /src/mongo
parentaa435e0f1303cd618b1df78ab086d5e06a52b1d3 (diff)
downloadmongo-adb1e5f25f3f5eacbbed382426542623b67632e5.tar.gz
SERVER-16200 Eliminate a redundant strlen in ThreadSafeString
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/util/goodies.h19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/mongo/util/goodies.h b/src/mongo/util/goodies.h
index 2a2991644c5..c4b90998c4e 100644
--- a/src/mongo/util/goodies.h
+++ b/src/mongo/util/goodies.h
@@ -124,7 +124,7 @@ namespace mongo {
public:
ThreadSafeString( size_t size=256 )
: _size( size ) , _buf( new char[size] ) {
- memset( _buf , 0 , _size );
+ memset( _buf , '\0' , _size );
}
~ThreadSafeString() {
@@ -132,25 +132,20 @@ namespace mongo {
}
std::string toString() const {
- std::string s = _buf;
- return s;
+ return _buf;
}
- ThreadSafeString& operator=( const char * str ) {
- size_t s = strlen(str);
+ ThreadSafeString& operator=( const StringData& str ) {
+ size_t s = str.size();
if ( s >= _size - 2 )
s = _size - 2;
- strncpy( _buf , str , s );
- _buf[s] = 0;
+ strncpy( _buf , str.rawData() , s );
+ _buf[s] = '\0';
return *this;
}
- ThreadSafeString& operator=(const string& str) {
- return (*this = str.c_str());
- }
-
bool empty() const {
- return _buf == 0 || _buf[0] == 0;
+ return _buf[0] == '\0';
}
private: