539 Commits

Author SHA1 Message Date
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
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
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
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
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
Milo Yip
1fafc38ee2 Merge pull request #122 from miloyip/issue114tmpnam
Replace tmpname() by mkstemp() on non-MSVC compilers
2014-08-29 00:01:12 +09:00
Milo Yip
e27f7e7123 Merge pull request #119 from miloyip/issue116extramemberapi
Three new APIs are added for JSON object type.
2014-08-28 23:41:32 +09:00
miloyip
6f4c83ad30 Replace tmpname() by mkstemp() on non-MSVC compilers 2014-08-28 22:19:56 +08:00
Milo Yip
991aeaa01c Merge pull request #115 from wrr/warningfix
Fix `RAPIDJSON_HAS_STDSTRING is not defined` compilation warning
2014-08-28 23:16:59 +09:00
Milo Yip
284dcf3dc5 Change MemberEmpty() to ObjectEmpty() 2014-08-28 20:25:41 +08:00
Milo Yip
8dfc97f5d6 Change PrettyWriter Allocator=MemoryPoolAllocator<> to StackAllocator = CrtAllocator
Fixes #118
2014-08-28 20:03:03 +08:00
Milo Yip
dc834c9c03 Add Value::MemberCount(), MemberEmpty(), RemoveAllMembers() 2014-08-27 23:14:17 +08:00
Milo Yip
b5928618d4 Merge pull request #112 from pah/fixes/111
Use local typedef to invoke GenericMember's destructor
2014-08-27 23:04:06 +09:00
Philipp A. Hartmann
a9add7bd2a GenericValue: add non-template overload for operator!=
As reported in #113, recent versions of Clang complain about
ambiguous overloads for some comparison operator instantiations,
especially if the deduced template type is a GenericValue.

Add an explicit, non-templated version for now (which is a better
match).

This only solves part of the problem, as comparisons between
  * GenericValue & GenericDocument
  * GenericValue with different SourceAllocator types
will still cause ambiguities.
2014-08-26 20:06:25 +02:00
Jan Wrobel
fa5b1efd23 Fix RAPIDJSON_HAS_STDSTRING is not defined compilation warning 2014-08-26 19:23:58 +02:00
Philipp A. Hartmann
db7a51041e Use local typedef to invoke GenericMember's destructor (fixes #111) 2014-08-26 15:36:20 +02:00
miloyip
38889835ce Add google test as submodule 2014-08-23 12:00:10 +08:00
miloyip
86802f8bf1 Remove gtest 2014-08-23 12:00:10 +08:00
Milo Yip
831d03d132 Merge pull request #110 from pah/fixes/memberiterator-comparisons
GenericMemberIterator: fix comparisons/differences for mixed-constness expressions
2014-08-21 17:01:43 +08:00
Philipp A. Hartmann
889f3fa9c0 valuetest: add tests for member iterator conversions/relations 2014-08-21 10:47:00 +02:00
Philipp A. Hartmann
26c24d0bd9 GenericMemberIterator: allow mixed-constness comparisons and differences 2014-08-21 10:45:23 +02:00
Philipp A. Hartmann
618fe2f4fc GenericValue::MemberErase: drop explicit iterator conversions 2014-08-21 10:40:13 +02:00
Milo Yip
ca5000ba67 Merge pull request #108 from miloyip/ParsingOptimization
Parsing optimization
2014-08-21 12:53:17 +08:00
miloyip
4f81c873a6 Optimize SkipWhitespace_SIMD()
Do unaligned non-SIMD matching first, and then SIMD matching later.
Also add a fast path for no skipping.
2014-08-20 17:49:30 +08:00
Milo Yip
df70ee8219 Merge pull request #107 from pah/feature/basic_string
GenericValue: add optional support for std::string
2014-08-20 15:19:19 +08:00
miloyip
fdc2b569db Optimize number parsing for 64-bit architecture 2014-08-20 15:17:21 +08:00
Philipp A. Hartmann
ae3e12d7df .travis.yml: include RAPIDJSON_HAS_STDSTRING tests 2014-08-20 07:08:01 +02:00
Philipp A. Hartmann
2e0b8730a1 add tests for RAPIDJSON_HAS_STDSTRING 2014-08-20 07:07:55 +02:00
Philipp A. Hartmann
744b4852ff GenericValue: add (optional) support for std::string
Some users may want to use RapidJSON with std::string objects.  This commits
adds an (opt-in) feature to include some basic support.  The implementation
uses std::basic_string<Ch> as generic string type.

Support currently covers:
 * construction
 * comparison

No special APIs for AddMember or PushBack have been added, as std::string
most probably requires copying (or an explicit StringRef() call).
2014-08-20 07:07:55 +02:00
Philipp A. Hartmann
702b45bb6e GenericValue: refactoring of operator==/!=
By restructuring the call forwarding of the various operator== and
operator!= overloads, new overloads can be added by simply adding an
additional member operator==.

Additionally, the "Ch*" overloads are dropped in favour of an SFINAE
version that removes the pointer variants from matching the templated
operator== (see also operator=).
2014-08-20 07:07:42 +02:00
Milo Yip
1adeecb12e Merge pull request #106 from pah/doc/config-error
Add Doxygen documentation for configuration macros and error handling
2014-08-20 09:19:09 +08:00
Philipp A. Hartmann
1621ba3a41 add Doxygen documentation for error handling customization 2014-08-19 19:13:01 +02:00
Philipp A. Hartmann
abcd6df2c0 add Doxygen documentation for configuration macros 2014-08-19 19:12:45 +02:00
Milo Yip
c0a7922db0 Merge pull request #105 from miloyip/MemoryOptimization
Memory optimization
2014-08-19 00:07:49 +08:00
Milo Yip
e3aa8f427c Remove unused macro 2014-08-17 20:55:49 +08:00
Milo Yip
d6513e251c Fix a gcc compilation error 2014-08-17 18:55:36 +08:00
Milo Yip
941aa93f45 Separate Document's value and stack allocator.
Use CrtAllocator for stack.
ShrinkToFit stack after parsing.
2014-08-17 18:33:47 +08:00
Milo Yip
3714019819 Add ShrinkToFit() to StringBuffer and MemoryBuffer 2014-08-17 18:32:08 +08:00
Milo Yip
2e23787753 Change Reader/Writer's stack allocator to CrtAllocator 2014-08-17 18:31:41 +08:00
Milo Yip
4a2ddf8075 Add Stack::ShrinkToFit() and some refactoring.
Lazy allocation. (so Document not for parsing don't need to allocate
stack).
Remove redundant stackCapacity member variable.
2014-08-17 18:29:37 +08:00
Milo Yip
4600680a56 Merge pull request #103 from pah/travis/32bit
.travis.yml: enable 32-bit builds
2014-08-13 14:33:21 +08:00