826 Commits

Author SHA1 Message Date
Kosta
17b1a14d62 add Key() method to Writer and PrettyWriter 2014-09-04 15:20:05 +02:00
Kosta
57e1c87553 add Key() method to the Handler concept
For more details see: https://github.com/miloyip/rapidjson/issues/132

This commit tries to minimize the required code changes and forwards the `Handler::Key()` calls to `Handler::String()` wherever possible in order to not break existing code; or at least not code deriving from `BaseReaderHandler` when implementing a custom `Handler`.
2014-09-04 15:14:18 +02:00
miloyip
b0436911a8 Check "fast path cases in disguise" in strtod 2014-09-03 14:45:37 +08:00
miloyip
818f6f1f2e Add random tests for ParseNumber 2014-09-03 13:27:43 +08:00
Milo Yip
bc9d7866be Merge pull request #128 from pah/feature/cxx11-move
Initial C++11 move support
2014-09-03 09:37:35 +08:00
Milo Yip
15d70d6a7b Merge pull request #127 from pah/feature/value-different-allocators
GenericValue: accept values with different allocators for read-only access
2014-09-03 09:37:15 +08:00
miloyip
0580d42d11 Fallback strtod() when not able to do fast-path
This shall generate best possible precision (if strtod() is correctly
implemented). Need more unit tests and performance tests. May add an
option for accepting precision error. Otherwise LUT in Pow10() can be
reduced.
2014-09-03 01:02:38 +08:00
Milo Yip
c6e6bca22f Merge pull request #130 from pah/fixes/capacity-growth
GenericValue: reduce growth factor for array/object reallocations
2014-09-02 22:11:34 +08:00
Milo Yip
9289f3270d Merge pull request #131 from Kosta-Github/Kosta/short_string_optimization
short string optimization
2014-09-02 21:52:10 +08:00
Kosta
08e81097eb final fix for the unit test case... 2014-09-01 12:54:50 +02:00
Kosta
ba05ea52cf use rapidjson::Value::SizeType as the type for storing and comparing the string length 2014-09-01 12:52:36 +02:00
Kosta
609997565c unit test simplification for short string optimization 2014-09-01 12:46:04 +02:00
Kosta
88debcf02e typo fixed for the unit test implementation 2014-09-01 12:40:28 +02:00
Kosta
056d0dafe4 add unit test for testing edge cases of the short string optimization 2014-09-01 12:34:43 +02:00
Kosta
697cf407c2 fixed a compiler error not caught by VS2012... 2014-09-01 12:01:25 +02:00
Kosta
d2a374b40c allow the short string optimization to store one more character
The `ShortString` can represent zero-terminated strings up to `MaxSize` chars (excluding the terminating zero) and store a value to determine the length of the contained string in the last character `str[LenPos]` by storing `MaxSize - length` there. If the string to store has the maximal length of `MaxSize` (excluding the terminating zero) then `str[LenPos]` will store `0` and therefore act as the string terminator as well. For getting the string length back from that value just use `MaxSize - str[LenPos]`.

This allows to store `11`-chars strings in 32-bit mode and `15`-chars strings in 64-bit mode inline (for `UTF8`-encoded strings).
2014-09-01 11:52:09 +02:00
Philipp A. Hartmann
0d2761a59c GenericValue: round up during capacity growth
Suggested-by: @miloyip
2014-09-01 11:31:25 +02:00
Kosta
b92d0ebd1b code cleanup for StringEqual()
Instead of replicating the functionality of `GetString()` and `GetStringLength()` in `StringEqual()` it now calls these methods instead.
2014-09-01 11:15:52 +02:00
Kosta
3caa86c923 short string optimization
Since the payload (the `Data` union) of the current implementation of `GenericValue` is `12 bytes` (32 bit) or `16 bytes` (64 bit) it could store `UTF8`-encoded strings up to `10` or `14` chars plus the `terminating zero` character plus the string length:
``` C++
    struct ShortString {
        enum { MaxSize = sizeof(GenericValue::String) / sizeof(Ch) - sizeof(unsigned char) };
        Ch str[MaxSize];
        unsigned char length;
    };  // at most as many bytes as "String" above => 12 bytes in 32-bit mode, 16 bytes in 64-bit mode

```

This is achieved by introducing additional `kInlineStrFlag` and `kShortStringFlag` flags. When setting a new string value in `SetStringRaw(s, alloc)` it is first checked if the string is short enough to fit into the `inline string buffer` and if so the given source string will be copied into the new `ShortString` target instead of allocating additional memory for it.
2014-09-01 11:11:26 +02:00
Philipp A. Hartmann
f4f432801a GenericValue: reduce growth factor for array/object reallocations
As mentioned by @kosta-github in http://git.io/0gkYSg, the currently
used growth factor of 2 is suboptimal for memory performance.  An
extensive discussion can be found at [1].

This patch reduces the array/object capacity growth factor to 1.5, as
many C++ implementations have chosen to use.  In order to avoid
floating-point arithmetics for computing the new capacity, I did not
add any customization parameter for the factor and used a shift+add
instead.

[1] https://github.com/facebook/folly/blob/master/folly/docs/FBVector.md
2014-09-01 08:57:21 +02:00
Milo Yip
2a4e055590 Merge pull request #129 from pah/bug/compare-uint64-double
Failing comparisons between certain (Ui|I)nt64 numbers
2014-09-01 12:09:31 +08:00
Philipp A. Hartmann
8ae2266c3b GenericStringRef: add NOEXCEPT, add ASSERT
* constructor from array is RAPIDJSON_NOEXCEPT
 * constructor from plain pointer missed an assert
2014-08-31 22:01:57 +02:00
Philipp A. Hartmann
56625bd9f0 GenericValue: add some more RAPIDJSON_NOEXCEPT
* Move()
 * RawAssign()
 * SetStringRaw()
2014-08-31 22:00:39 +02:00
Philipp A. Hartmann
fd2ba0bc44 GenericValue: fix comparison of (Ui|I)nt64 numbers
Some 64-bit integers cannot be represented losslessly as a double.
Due to a typo in the operator==, the comparison has been performed
after a double conversion in too many cases.
2014-08-31 19:01:16 +02:00
Philipp A. Hartmann
47c32eee6b valuetest: add test for Uint64 comparisons 2014-08-31 19:01:16 +02:00
Philipp A. Hartmann
5672d24651 GenericValue: add RAPIDJSON_NOEXCEPT
Added basic detection of `noexcept` support for some compilers, added
corresponding RAPIDJSON_NOEXCEPT annotations to
 * non-allocating constructors
 * (move) assignment
 * Swap
2014-08-31 17:42:18 +02:00
Philipp A. Hartmann
36031b1b6f valuetest: add tests for rvalue references, reenable erase/remove pattern 2014-08-31 17:32:31 +02:00
Philipp A. Hartmann
b5f9d60765 GenericValue: add rvalue-ref overloads to AddMember/PushBack
Directly allows temporary GenericValues as parameters:
  v.AddMember("foo", Value(s.c_str(),alloc), alloc);
2014-08-31 17:32:31 +02:00
Philipp A. Hartmann
a9d2b75179 valuetest: avoid underscores in GoogleTest tests
See https://code.google.com/p/googletest/wiki/FAQ#Why_should_not_test_case_names_and_test_names_contain_underscore
2014-08-31 17:32:31 +02:00
Philipp A. Hartmann
c1c9ba7c59 always define RAPIDJSON_HAS_STDSTRING (default: 0) 2014-08-31 17:32:31 +02:00
Philipp A. Hartmann
5656078a38 detect rvalue reference support (RAPIDJSON_HAS_CXX11_RVALUE_REFS) 2014-08-31 17:32:31 +02:00
Philipp A. Hartmann
a16fe366ed rapidjson.h: add RAPIDJSON_GNUC as GCC version shortcut 2014-08-31 17:32:31 +02:00
Philipp A. Hartmann
5f6967b083 meta.h: disallow direct inclusion 2014-08-31 17:32:31 +02:00
Philipp A. Hartmann
defc3aaf9b always include "meta.h", as it is not only used for member iterators 2014-08-31 15:04:45 +02:00
Philipp A. Hartmann
1beec85453 GenericValue: add move constructor/move assignment
When C++11 is enabled, several algorithms will fail, if GenericValue is
neither copyable, nor movable.

Cherry-picked from 8005b55.
2014-08-31 12:25:00 +02:00
Philipp A. Hartmann
a2a0d16167 unittest.h: simplify AssertException
Some compilers warn about the missing initialisation of the std::exception
base class of the AssertException helper.  The simplest solution is to
inherit from std::logic_error instead, which provides all of the required
functionality already.
2014-08-31 11:08:33 +02:00
Philipp A. Hartmann
ffed1d67c1 valuetest: more testing of MemberCount 2014-08-31 11:01:05 +02:00
Philipp A. Hartmann
c597505761 valuetest: test member operations with different allocators 2014-08-31 11:01:05 +02:00
Philipp A. Hartmann
f8db473779 GenericValue: add explicit operator!=(const Ch*)
MSVC'2005 needs an explicit overload for operator!=(const Ch*)
after the addition of the IsGenericValue SFINAE restrictions.
2014-08-31 11:01:05 +02:00
Philipp A. Hartmann
a40dcb9525 valuetest: always test comparisons with different allocators 2014-08-31 11:01:05 +02:00
Philipp A. Hartmann
1da0784331 GenericValue: add and use IsGenericValue meta function
This commit adds an IsGenericValue meta function to match arbitrary
instantiations of the GenericValue template (or derived classes).

This meta function is used in the SFINAE-checks to avoid matching
the generic APIs (operator=,==,!=; AddMember, PushBack) for instances
of the main template.  This avoids ambiguities with the GenericValue
overloads.
2014-08-31 11:01:05 +02:00
Philipp A. Hartmann
e294ce6f7a GenericValue: accept different allocators for read-only access
Several GenericValue functions take a const-reference to another GenericValue
only.  These functions can safely accept values with a different allocator
type.

The following functions are therefore extended by a SourceAllocator template
parameter in this commit:

 - operator==/!=/[]
 - HasMember, FindMember, RemoveMember
 - StringEqual
2014-08-31 11:01:05 +02:00
Milo Yip
ab8416e1e6 Merge pull request #125 from pah/fixes/113
Fix comparison operator ambiguities between Value/Document
2014-08-31 07:31:45 +08:00
Philipp A. Hartmann
804b7fcb2f GenericValue: add static assert to catch broken SFINAE
Before applying the simplifications in ed282b814, the SFINAE check for the
GenericValue(bool) constructor has been broken in MSVC 2005. Add a static
assert as a safe-guard against future reappearance of this problem.
2014-08-30 16:39:15 +02:00
Philipp A. Hartmann
fdd7a76386 GenericValue: use IsBaseOf to support comparisons between Value/Document
This finally fixes #113.
2014-08-30 16:10:59 +02:00
Philipp A. Hartmann
f076faca3d meta.h: add IsBaseOf meta function
In order to match GenericValue and its derived classes for the
SFINAE-implementation of some of the operators/functions, this
meta-function matches all types equal to or derived from a given
class.  See std::is_base_of<B,D> available in C++11.

Define RAPIDJSON_HAS_CXX_TYPETRAITS to use the C++11 implementation.
2014-08-30 16:10:53 +02:00
Philipp A. Hartmann
ed282b8141 meta.h: simplify meta programming helpers
Some (older) compilers have problems with compile-time constants.
This commit simplifies the implementation of the helper classes
in order to improve compiler support, especially be removing the
need of partial template specialisation.

No functional changes.
2014-08-30 15:55:06 +02:00
Philipp A. Hartmann
b56641106b improve EN/DISABLEIF macros to support complex templated parameters 2014-08-30 12:52:36 +02:00
Philipp A. Hartmann
d63a40a05d valuetest: extended value comparison tests
Prepare equalto_operator tests to test comparisons between
 * GenericValue and GenericDocument
 * GenericValue with different SourceAllocator types

Both combinations currently fail due to ambiguities with the
templated operators on several compilers.
2014-08-30 12:39:39 +02:00
miloyip
a46d152218 Merge branch 'master' into issue120floatprecision 2014-08-28 23:05:27 +08:00