miloyip/rapidjson — pull request #64 by pah (2014-07-11 09:24:14+00:00)
Title: Improve exception safety and add support for swtiching error handling to exceptions

This pull-request slightly adjusts the current error handling code to improve exception safety and enable switching the error handling to user-defined exceptions (by defining `RAPIDJSON_PARSE_ERROR_EARLY_RETURN`). An example of such a user-defined exception can be found in pah/rapidjson-upstream@bc0cca12 (not intended for upstream inclusion).

The main changes are:
* moving `ParseErrorCode` to `include/rapidjson/error/error.h`
* clearing Document and Reader stacks from a destructor
* adding `ParseResult` class to propagate error code and offset together

Benchmarking results below, details available at https://gist.github.com/pah/4f5cc9d65e653e40747c
The third column is just to shows the impact of actually using an exception to propagate an error.

**Linux 64-bit, Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz**

| Compiler | Baseline | `exception-support` | `exception-throw` |
| ---------- | --------- | ------------------- | ----------------- |
| GCC 4.4 | 11826 ms | 11896 ms | 12029 ms |
| GCC 4.6 | 12730 ms | 13218 ms | 12661 ms |
| GCC 4.8 | 9847 ms | 9817 ms | 10467 ms |
| GCC 4.9 | 9833 ms | 10067 ms | 10285 ms |
| Clang 3.5 | 11172 ms | 10867 ms | 11165 ms |

**Linux 32-bit, Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz**

| Compiler | Baseline | `exception-support` | `exception-throw` |
| ---------- | --------- | ------------------- | ----------------- |
| GCC 4.4 | 14545 ms | 14571 ms | 14408 ms |
| GCC 4.6 | 14877 ms | 15197 ms | 15126 ms |
| GCC 4.8 | 11341 ms | 11378 ms | 11971 ms |
| GCC 4.9 | 11649 ms | 11498 ms | 12175 ms |
| Clang 3.5 | 12683 ms | 13038 ms | 12750 ms |

**Linux 32-bit, Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz (no SSE4.2)**

| Compiler | Baseline | `exception-support` | `exception-throw` |
| ---------- | --------- | ------------------- | ----------------- |
| GCC 4.4 | 21160 ms | 21199 ms | 20627 ms |
| GCC 4.6 | 20933 ms | 21717 ms | 22107 ms |
| GCC 4.8 | 17192 ms | 17377 ms | 18168 ms |
| GCC 4.9 | 18510 ms | 17703 ms | 18364 ms |
| Clang 3.5 | 17565 ms | 17575 ms | 17477 ms |

Performance details: https://gist.github.com/pah/4f5cc9d65e653e40747c