… | |
… | |
71 | # define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1)) |
71 | # define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1)) |
72 | #else |
72 | #else |
73 | # define JSON_SLOW 0 |
73 | # define JSON_SLOW 0 |
74 | # define JSON_STASH json_stash |
74 | # define JSON_STASH json_stash |
75 | #endif |
75 | #endif |
|
|
76 | |
|
|
77 | // the amount of HEs to allocate on the stack, when sorting keys |
|
|
78 | #define STACK_HES 64 |
76 | |
79 | |
77 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
80 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
78 | static SV *json_true, *json_false; |
81 | static SV *json_true, *json_false; |
79 | |
82 | |
80 | enum { |
83 | enum { |
… | |
… | |
592 | } |
595 | } |
593 | |
596 | |
594 | if (count) |
597 | if (count) |
595 | { |
598 | { |
596 | int i, fast = 1; |
599 | int i, fast = 1; |
597 | #if defined(__BORLANDC__) || defined(_MSC_VER) |
600 | HE *hes_stack [STACK_HES]; |
598 | HE **hes = _alloca (count * sizeof (HE)); |
601 | HE **hes = hes_stack; |
599 | #else |
602 | |
600 | HE *hes [count]; // if your compiler dies here, you need to enable C99 mode |
603 | // allocate larger arrays on the heap |
601 | #endif |
604 | if (count > STACK_HES) |
|
|
605 | { |
|
|
606 | SV *sv = sv_2mortal (NEWSV (0, count * sizeof (*hes))); |
|
|
607 | hes = (HE **)SvPVX (sv); |
|
|
608 | } |
602 | |
609 | |
603 | i = 0; |
610 | i = 0; |
604 | while ((he = hv_iternext (hv))) |
611 | while ((he = hv_iternext (hv))) |
605 | { |
612 | { |
606 | hes [i++] = he; |
613 | hes [i++] = he; |
… | |
… | |
1805 | json_boolean_stash = 0; |
1812 | json_boolean_stash = 0; |
1806 | |
1813 | |
1807 | void new (char *klass) |
1814 | void new (char *klass) |
1808 | PPCODE: |
1815 | PPCODE: |
1809 | { |
1816 | { |
1810 | SV *pv = NEWSV (0, sizeof (JSON)); |
1817 | SV *pv = NEWSV (0, sizeof (JSON)); |
1811 | SvPOK_only (pv); |
1818 | SvPOK_only (pv); |
1812 | json_init ((JSON *)SvPVX (pv)); |
1819 | json_init ((JSON *)SvPVX (pv)); |
1813 | XPUSHs (sv_2mortal (sv_bless ( |
1820 | XPUSHs (sv_2mortal (sv_bless ( |
1814 | newRV_noinc (pv), |
1821 | newRV_noinc (pv), |
1815 | strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1) |
1822 | strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1) |