Skip to content

Commit

Permalink
Some small optimizations in JSON encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
aslze committed Dec 2, 2023
1 parent ac07ca0 commit b5fb994
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Xdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,10 @@ void XdlEncoder::_encode(const Var& v)
int n = v.length();
const Var& v0 = n>0? v[0] : v;
bool multi = (_pretty && (n > 10 || (n>0 && (v0.is(Var::ARRAY) || v0.is(Var::DIC)))));
if (!multi && v0.is(Var::STRING))
if (_pretty && !multi && v0.is(Var::STRING))
{
for(int i = 0; i < n; i++)
if (v[i].length() > 10)
for (int i = 0, m = 0; i < n; i++)
if ((m += v[i].length()) > 100)
{
multi = true;
break;
Expand Down Expand Up @@ -774,7 +774,8 @@ void XdlEncoder::_encode(const Var& v)
else
begin_object("");
int k = (hasclass && _json)?1:0;
_indent = String::repeat(INDENT_CHAR, ++_level);
if (_pretty)
_indent = String::repeat(INDENT_CHAR, ++_level);
foreach2(String& name, Var& value, v)
{
if(value.ok() && (_json || name != ASL_XDLCLASS))
Expand Down

0 comments on commit b5fb994

Please sign in to comment.