@@ -350,7 +350,7 @@ class document {
350
350
std::unique_ptr<uint8_t []> string_buf;
351
351
352
352
private:
353
- inline error_code set_capacity (size_t len) noexcept ;
353
+ inline error_code allocate (size_t len) noexcept ;
354
354
template <typename T>
355
355
friend class simdjson ::minify;
356
356
friend class parser ;
@@ -609,13 +609,10 @@ class parser {
609
609
* @param max_capacity The maximum document length the parser can automatically handle. The parser
610
610
* will allocate more capacity on an as needed basis (when it sees documents too big to handle)
611
611
* up to this amount. The parser still starts with zero capacity no matter what this number is:
612
- * to allocate an initial capacity, call set_capacity() after constructing the parser. Defaults
613
- * to SIMDJSON_MAXSIZE_BYTES (the largest single document simdjson can process).
614
- * @param max_depth The maximum depth--number of nested objects and arrays--this parser can handle.
615
- * This will not be allocated until parse() is called for the first time. Defaults to
616
- * DEFAULT_MAX_DEPTH.
612
+ * to allocate an initial capacity, call allocate() after constructing the parser.
613
+ * Defaults to SIMDJSON_MAXSIZE_BYTES (the largest single document simdjson can process).
617
614
*/
618
- really_inline parser (size_t max_capacity = SIMDJSON_MAXSIZE_BYTES, size_t max_depth = DEFAULT_MAX_DEPTH ) noexcept ;
615
+ really_inline parser (size_t max_capacity = SIMDJSON_MAXSIZE_BYTES) noexcept ;
619
616
620
617
/* *
621
618
* Take another parser's buffers and state.
@@ -835,6 +832,30 @@ class parser {
835
832
/* * @private We do not want to allow implicit conversion from C string to std::string. */
836
833
really_inline simdjson_result<element> parse_many (const char *buf, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept = delete;
837
834
835
+ /* *
836
+ * Ensure this parser has enough memory to process JSON documents up to `capacity` bytes in length
837
+ * and `max_depth` depth.
838
+ *
839
+ * @param capacity The new capacity.
840
+ * @param max_depth The new max_depth. Defaults to DEFAULT_MAX_DEPTH.
841
+ * @return The error, if there is one.
842
+ */
843
+ WARN_UNUSED inline error_code allocate (size_t capacity, size_t max_depth = DEFAULT_MAX_DEPTH) noexcept ;
844
+
845
+ /* *
846
+ * @private deprecated because it returns bool instead of error_code, which is our standard for
847
+ * failures. Use allocate() instead.
848
+ *
849
+ * Ensure this parser has enough memory to process JSON documents up to `capacity` bytes in length
850
+ * and `max_depth` depth.
851
+ *
852
+ * @param capacity The new capacity.
853
+ * @param max_depth The new max_depth. Defaults to DEFAULT_MAX_DEPTH.
854
+ * @return true if successful, false if allocation failed.
855
+ */
856
+ [[deprecated(" Use allocate() instead." )]]
857
+ WARN_UNUSED inline bool allocate_capacity (size_t capacity, size_t max_depth = DEFAULT_MAX_DEPTH) noexcept ;
858
+
838
859
/* *
839
860
* The largest document this parser can support without reallocating.
840
861
*
@@ -858,17 +879,6 @@ class parser {
858
879
*/
859
880
really_inline size_t max_depth () const noexcept ;
860
881
861
- /* *
862
- * Set capacity. This is the largest document this parser can support without reallocating.
863
- *
864
- * This will allocate or deallocate as necessary.
865
- *
866
- * @param capacity The new capacity, in bytes.
867
- *
868
- * @return MEMALLOC if unsuccessful, SUCCESS otherwise.
869
- */
870
- WARN_UNUSED inline error_code set_capacity (size_t capacity) noexcept ;
871
-
872
882
/* *
873
883
* Set max_capacity. This is the largest document this parser can automatically support.
874
884
*
@@ -880,32 +890,6 @@ class parser {
880
890
*/
881
891
really_inline void set_max_capacity (size_t max_capacity) noexcept ;
882
892
883
- /* *
884
- * Set the maximum level of nested object and arrays supported by this parser.
885
- *
886
- * This will allocate or deallocate as necessary.
887
- *
888
- * @param max_depth The new maximum depth, in bytes.
889
- *
890
- * @return MEMALLOC if unsuccessful, SUCCESS otherwise.
891
- */
892
- WARN_UNUSED inline error_code set_max_depth (size_t max_depth) noexcept ;
893
-
894
- /* *
895
- * @private @deprecated Use set_capacity() instead.
896
- *
897
- * Ensure this parser has enough memory to process JSON documents up to `capacity` bytes in length
898
- * and `max_depth` depth.
899
- *
900
- * Equivalent to calling set_capacity() and set_max_depth().
901
- *
902
- * @param capacity The new capacity.
903
- * @param max_depth The new max_depth. Defaults to DEFAULT_MAX_DEPTH.
904
- * @return true if successful, false if allocation failed.
905
- */
906
- [[deprecated(" Use set_capacity() instead." )]]
907
- WARN_UNUSED inline bool allocate_capacity (size_t capacity, size_t max_depth = DEFAULT_MAX_DEPTH) noexcept ;
908
-
909
893
/* * @private Use the new DOM API instead */
910
894
class Iterator ;
911
895
/* * @private Use simdjson_error instead */
@@ -988,25 +972,25 @@ class parser {
988
972
989
973
private:
990
974
/* *
991
- * The maximum document length this parser supports .
975
+ * The maximum document length this parser will automatically support .
992
976
*
993
- * Buffers are large enough to handle any document up to this length .
977
+ * The parser will not be automatically allocated above this amount .
994
978
*/
995
- size_t _capacity{ 0 } ;
979
+ size_t _max_capacity ;
996
980
997
981
/* *
998
- * The maximum document length this parser will automatically support .
982
+ * The maximum document length this parser supports .
999
983
*
1000
- * The parser will not be automatically allocated above this amount .
984
+ * Buffers are large enough to handle any document up to this length .
1001
985
*/
1002
- size_t _max_capacity ;
986
+ size_t _capacity{ 0 } ;
1003
987
1004
988
/* *
1005
989
* The maximum depth (number of nested objects and arrays) supported by this parser.
1006
990
*
1007
991
* Defaults to DEFAULT_MAX_DEPTH.
1008
992
*/
1009
- size_t _max_depth;
993
+ size_t _max_depth{ 0 } ;
1010
994
1011
995
/* *
1012
996
* The loaded buffer (reused each time load() is called)
0 commit comments