[SERVER-1269] BSON headers provide no way to give the length of a c string when used as a key or value Created: 21/Jun/10  Updated: 24/Jan/15  Resolved: 20/Jan/15

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 1.5.3
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Andrew Morrow (Inactive) Assignee: Andrew Morrow (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All


Issue Links:
Depends
depends on SERVER-1452 Prevent unnecessary c_str() calling i... Closed
Backwards Compatibility: Fully Compatible
Participants:

 Description   

Consider the following code:

const char kKey[] = "key";
const char kValue[] = "value";
someBSONObjBuilder.append(key, value);

This is going to cause two calls to strlen which certainly don't need to be made, since the lengths of kKey and kValue are known at compile time. For such cases, it would be nice to have a mechanism to pass the already known size down to the BSONObjBuilder:

someBSONObjBuilder.append(key, sizeof(key), value, sizeof(value));

Similar overloads would need to be made for each type'd BSONObjBuilder::append(key, sizeof(key), T), and for BSONArrayBuilder.



 Comments   
Comment by auto [ 23/Jul/10 ]

Author:

{'login': 'alerner', 'name': 'Alberto Lerner', 'email': 'alerner@10gen.com'}

Message: SERVER-1269 TODO
http://github.com/mongodb/mongo/commit/1d83bd2e990ed4dc2ef8fabef5767667b61e1622

Comment by Alberto Lerner [ 23/Jul/10 ]

Second parameter still can't take a StringData argument but the first parameter can already skip the unnecessary strlen()

example usage:
StringData c( "key", StringData::LiteralTag() );
BSONObjBuilder builder;
builder.append( c, "value");

Generated at Thu Feb 08 02:56:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.