Skip to content

Commit

Permalink
Add doc, remove old macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Antares0982 committed Nov 25, 2024
1 parent 3727837 commit 07bf50c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
29 changes: 26 additions & 3 deletions src/encode/encode_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,17 +789,39 @@ force_inline bool vec_in_boundary(UnicodeVector *vec) {

/*
* Some utility functions only related to *write*, like vector reserve, writing number
* need macro: COMPILE_WRITE_UCS_LEVEL, value: 1, 2, or 4
* need macro: COMPILE_WRITE_UCS_LEVEL, value: 1, 2, or 4.
*/
#include "encode_utils_impl_wrap.inl"

/*
* Some utility functions related to SIMD, like getting escape mask,
* elevating ucs level, read/write simd vars.
* need macro:
* COMPILE_READ_UCS_LEVEL, value: 1, 2, or 4.
* COMPILE_WRITE_UCS_LEVEL, value: 1, 2, or 4.
*/
#include "encode_simd_utils_wrap.inl"

/*
* Some functions for writing the unicode vector, like writing key, writing value str.
* need macro:
* COMPILE_READ_UCS_LEVEL, value: 1, 2, or 4.
* COMPILE_WRITE_UCS_LEVEL, value: 1, 2, or 4.
*/
#include "encode_unicode_impl_wrap.inl"

/*
* Top-level encode functions, like encode list, encode dict, encode single unicode.
* need macro:
* COMPILE_UCS_LEVEL, value: 0, 1, 2, or 4. COMPILE_UCS_LEVEL is the current writing level.
* This differs from COMPILE_WRITE_UCS_LEVEL: `0` stands for ascii. Since we always start from
* writing ascii, `0` also defines the entrance of encoding. See `PYYJSON_DUMPS_OBJ` for more
* details.
* COMPILE_INDENT_LEVEL, value: 0, 2, or 4.
*/
#include "encode_impl_wrap.inl"


/* Encodes non-container types. */
force_inline PyObject *pyyjson_dumps_single_unicode(PyObject *unicode) {
UnicodeVector *vec = PyObject_Malloc(PYYJSON_ENCODE_DST_BUFFER_INIT_SIZE);
RETURN_ON_UNLIKELY_ERR(!vec);
Expand All @@ -812,7 +834,7 @@ force_inline PyObject *pyyjson_dumps_single_unicode(PyObject *unicode) {
U8_WRITER(vec) = (u8 *) (((PyCompactUnicodeObject *) vec) + 1);
}
void *write_start = (void *) U8_WRITER(vec);
vec->head.write_end = (void *) ((u8 *) vec + PYYJSON_ENCODE_DST_BUFFER_INIT_SIZE);
vec->head.write_end = (void *) (((u8 *) vec) + PYYJSON_ENCODE_DST_BUFFER_INIT_SIZE);
bool success;
switch (unicode_kind) {
// pass `is_in_obj = true` to avoid unwanted indent check
Expand Down Expand Up @@ -902,6 +924,7 @@ force_inline PyObject *pyyjson_dumps_single_float(PyObject *val) {
return unicode;
}

/* Entrance for python code. */
force_noinline PyObject *pyyjson_Encode(PyObject *self, PyObject *args, PyObject *kwargs) {
PyObject *obj;
int option_digit = 0;
Expand Down
22 changes: 2 additions & 20 deletions src/pyyjson_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
#ifndef PYYJSON_STRING_BUFFER_SIZE
#define PYYJSON_STRING_BUFFER_SIZE (512 * 1024)
#endif

/* Buffer for key associative cache. Default cost: 2048 * sizeof(pyyjson_cache_type) = 16kb (per thread). */
#ifndef PYYJSON_KEY_CACHE_SIZE
#define PYYJSON_KEY_CACHE_SIZE (1 << 11)
#endif

/* Stack buffer for PyObject*. Default cost: 8 * 1024 = 8kb (per thread). */
#ifndef PYYJSON_OBJSTACK_BUFFER_SIZE
#define PYYJSON_OBJSTACK_BUFFER_SIZE (1024)
Expand All @@ -44,14 +46,6 @@
#define PYYJSON_ENCODE_DST_BUFFER_INIT_SIZE (1024)
#endif

/*
Init buffer size for op buffer.
Cost: PYYJSON_ENCODE_OP_BUFFER_INIT_SIZE * sizeof(void*) bytes per thread.
*/
#ifndef PYYJSON_ENCODE_OP_BUFFER_INIT_SIZE
#define PYYJSON_ENCODE_OP_BUFFER_INIT_SIZE (1024)
#endif

/*
Max nested structures for encoding.
Cost: PYYJSON_ENCODE_MAX_RECURSION * sizeof(void*) * 2 bytes per thread.
Expand All @@ -60,18 +54,6 @@
#define PYYJSON_ENCODE_MAX_RECURSION (1024)
#endif

#ifndef PYYJSON_ENCODE_ADDR_DESC_BUFFER_INIT_SIZE
#define PYYJSON_ENCODE_ADDR_DESC_BUFFER_INIT_SIZE ((Py_ssize_t)1 << 14)
#endif

#ifndef PYYJSON_ENCODE_OBJ_VIEW_BUFFER_INIT_SIZE
#define PYYJSON_ENCODE_OBJ_VIEW_BUFFER_INIT_SIZE ((Py_ssize_t)1 << 14)
#endif

#ifndef PYYJSON_ENCODE_VIEW_DATA_BUFFER_INIT_SIZE
#define PYYJSON_ENCODE_VIEW_DATA_BUFFER_INIT_SIZE ((Py_ssize_t)1 << 14)
#endif

/*
When a character needs escape when encoding,
the following `PYYJSON_ENCODE_ESCAPE_ONCE_BYTES`
Expand Down

0 comments on commit 07bf50c

Please sign in to comment.