-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 1.5.3
-
Component/s: Internal Client
-
None
-
Environment:All
std::string objects have known lengths. In the current implementation of the BSON library, std::string objects used as keys or values are converted to const char*'s with std::string::c_str(), and then passed to the const char* overload:
/** add a subobject as a member */
BSONObjBuilder& append(const string& fieldName , BSONObj subObj) {
return append( fieldName.c_str() , subObj );
}
That eventually makes its way to BufBuilder::append, where it calls strlen, unnecessarily recomputing the length:
void append(const char *str) {
append((void*) str, strlen(str)+1);
}
Given that std::string objects have known lengths, the call to strlen is a complete waste of time.