anhero / JsonBox

This is a JSON C++ library. It can write and read JSON files with ease and speed.
MIT License
115 stars 60 forks source link

[] and = operator always new memory? setInt setString will save much memory? #21

Closed cnsoft closed 9 years ago

cnsoft commented 10 years ago

e.g:
val["positionx"] = 10; val["positionx"].setInt(10);

is there some different with the two different function call?

madbranch commented 9 years ago

The operator= for the class Value has only been defined as

Value &operator=(const Value &src);

So when you write:

val["positionx"] = 10;

A Value instance is implicitly created using the following constructor:

Value(int newInt);

So in your example, the call to setInt(10) is probably much faster than using the operator=

To improve the operator=, I will overload the operator= to accept the same types as the constructors.