@@ -225,14 +225,8 @@ bool Value::CZString::isStaticString() const { return index_ == noDuplication; }
225
225
* memset( this, 0, sizeof(Value) )
226
226
* This optimization is used in ValueInternalMap fast allocator.
227
227
*/
228
- Value::Value (ValueType type)
229
- : type_(type), allocated_(false )
230
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
231
- ,
232
- itemIsUsed_ (0 )
233
- #endif
234
- ,
235
- comments_ (0 ), start_(0 ), limit_(0 ) {
228
+ Value::Value (ValueType type) {
229
+ initBasic (type);
236
230
switch (type) {
237
231
case nullValue:
238
232
break ;
@@ -267,130 +261,62 @@ Value::Value(ValueType type)
267
261
}
268
262
}
269
263
270
- Value::Value (UInt value)
271
- : type_(uintValue), allocated_(false )
272
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
273
- ,
274
- itemIsUsed_ (0 )
275
- #endif
276
- ,
277
- comments_ (0 ), start_(0 ), limit_(0 ) {
278
- value_.uint_ = value;
279
- }
280
-
281
- Value::Value (Int value)
282
- : type_(intValue), allocated_(false )
283
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
284
- ,
285
- itemIsUsed_ (0 )
286
- #endif
287
- ,
288
- comments_ (0 ), start_(0 ), limit_(0 ) {
264
+ Value::Value (Int value) {
265
+ initBasic (intValue);
289
266
value_.int_ = value;
290
267
}
291
268
269
+ Value::Value (UInt value) {
270
+ initBasic (uintValue);
271
+ value_.uint_ = value;
272
+ }
292
273
#if defined(JSON_HAS_INT64)
293
- Value::Value (Int64 value)
294
- : type_(intValue), allocated_(false )
295
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
296
- ,
297
- itemIsUsed_ (0 )
298
- #endif
299
- ,
300
- comments_ (0 ), start_(0 ), limit_(0 ) {
274
+ Value::Value (Int64 value) {
275
+ initBasic (intValue);
301
276
value_.int_ = value;
302
277
}
303
-
304
- Value::Value (UInt64 value)
305
- : type_(uintValue), allocated_(false )
306
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
307
- ,
308
- itemIsUsed_ (0 )
309
- #endif
310
- ,
311
- comments_ (0 ), start_(0 ), limit_(0 ) {
278
+ Value::Value (UInt64 value) {
279
+ initBasic (uintValue);
312
280
value_.uint_ = value;
313
281
}
314
282
#endif // defined(JSON_HAS_INT64)
315
283
316
- Value::Value (double value)
317
- : type_(realValue), allocated_(false )
318
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
319
- ,
320
- itemIsUsed_ (0 )
321
- #endif
322
- ,
323
- comments_ (0 ), start_(0 ), limit_(0 ) {
284
+ Value::Value (double value) {
285
+ initBasic (realValue);
324
286
value_.real_ = value;
325
287
}
326
288
327
- Value::Value (const char * value)
328
- : type_(stringValue), allocated_(true )
329
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
330
- ,
331
- itemIsUsed_ (0 )
332
- #endif
333
- ,
334
- comments_ (0 ), start_(0 ), limit_(0 ) {
289
+ Value::Value (const char * value) {
290
+ initBasic (stringValue, true );
335
291
value_.string_ = duplicateStringValue (value);
336
292
}
337
293
338
- Value::Value (const char * beginValue, const char * endValue)
339
- : type_(stringValue), allocated_(true )
340
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
341
- ,
342
- itemIsUsed_ (0 )
343
- #endif
344
- ,
345
- comments_ (0 ), start_(0 ), limit_(0 ) {
294
+ Value::Value (const char * beginValue, const char * endValue) {
295
+ initBasic (stringValue, true );
346
296
value_.string_ =
347
297
duplicateStringValue (beginValue, (unsigned int )(endValue - beginValue));
348
298
}
349
299
350
- Value::Value (const std::string& value)
351
- : type_(stringValue), allocated_(true )
352
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
353
- ,
354
- itemIsUsed_ (0 )
355
- #endif
356
- ,
357
- comments_ (0 ), start_(0 ), limit_(0 ) {
300
+ Value::Value (const std::string& value) {
301
+ initBasic (stringValue, true );
358
302
value_.string_ =
359
303
duplicateStringValue (value.c_str (), (unsigned int )value.length ());
360
304
}
361
305
362
- Value::Value (const StaticString& value)
363
- : type_(stringValue), allocated_(false )
364
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
365
- ,
366
- itemIsUsed_ (0 )
367
- #endif
368
- ,
369
- comments_ (0 ), start_(0 ), limit_(0 ) {
306
+ Value::Value (const StaticString& value) {
307
+ initBasic (stringValue);
370
308
value_.string_ = const_cast <char *>(value.c_str ());
371
309
}
372
310
373
311
#ifdef JSON_USE_CPPTL
374
- Value::Value (const CppTL::ConstString& value)
375
- : type_(stringValue), allocated_(true )
376
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
377
- ,
378
- itemIsUsed_ (0 )
379
- #endif
380
- ,
381
- comments_ (0 ), start_(0 ), limit_(0 ) {
312
+ Value::Value (const CppTL::ConstString& value) {
313
+ initBasic (stringValue, true );
382
314
value_.string_ = duplicateStringValue (value, value.length ());
383
315
}
384
316
#endif
385
317
386
- Value::Value (bool value)
387
- : type_(booleanValue), allocated_(false )
388
- #ifdef JSON_VALUE_USE_INTERNAL_MAP
389
- ,
390
- itemIsUsed_ (0 )
391
- #endif
392
- ,
393
- comments_ (0 ), start_(0 ), limit_(0 ) {
318
+ Value::Value (bool value) {
319
+ initBasic (booleanValue);
394
320
value_.bool_ = value;
395
321
}
396
322
@@ -966,6 +892,17 @@ Value& Value::operator[](const char* key) {
966
892
return resolveReference (key, false );
967
893
}
968
894
895
+ void Value::initBasic (ValueType type, bool allocated) {
896
+ type_ = type;
897
+ allocated_ = allocated;
898
+ #ifdef JSON_VALUE_USE_INTERNAL_MAP
899
+ itemIsUsed_ = 0 ;
900
+ #endif
901
+ comments_ = 0 ;
902
+ start_ = 0 ;
903
+ limit_ = 0 ;
904
+ }
905
+
969
906
Value& Value::resolveReference (const char * key, bool isStatic) {
970
907
JSON_ASSERT_MESSAGE (
971
908
type_ == nullValue || type_ == objectValue,
0 commit comments