Skip to content

Commit 26abb47

Browse files
committed
Code clean up
1 parent a5419d5 commit 26abb47

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

jsoniter-scala-macros/shared/src/main/scala-2/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,7 @@ object JsonCodecMaker {
19621962
} else if (fTpe <:< typeOf[Array[_]]) {
19631963
val cond =
19641964
if (cfg.transientEmpty) {
1965-
q"v.length > 0 && !${withEqualsFor(fTpe, q"v", d)(genArrayEquals(fTpe))}"
1965+
q"v.length != 0 && !${withEqualsFor(fTpe, q"v", d)(genArrayEquals(fTpe))}"
19661966
} else q"!${withEqualsFor(fTpe, q"v", d)(genArrayEquals(fTpe))}"
19671967
q"""val v = x.${fieldInfo.getter}
19681968
if ($cond) {
@@ -1997,7 +1997,7 @@ object JsonCodecMaker {
19971997
}"""
19981998
} else if (cfg.transientEmpty && fTpe <:< typeOf[Array[_]]) {
19991999
q"""val v = x.${fieldInfo.getter}
2000-
if (v.length > 0) {
2000+
if (v.length != 0) {
20012001
..${genWriteConstantKey(fieldInfo.mappedName)}
20022002
..${genWriteVal(q"v", fTpe :: types, fieldInfo.isStringified, EmptyTree)}
20032003
}"""

jsoniter-scala-macros/shared/src/main/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,7 @@ object JsonCodecMaker {
13821382
def genWriteConstantVal(value: String, out: Expr[JsonWriter])(using Quotes): Expr[Unit] =
13831383
if (isEncodingRequired(value)) '{ $out.writeVal(${Expr(value)}) }
13841384
else '{ $out.writeNonEscapedAsciiVal(${Expr(value)}) }
1385+
13851386
def genWriteArray[T: Type](x: Expr[Iterable[T]], writeVal: Quotes ?=> (Expr[JsonWriter], Expr[T]) => Expr[Unit],
13861387
out: Expr[JsonWriter])(using Quotes): Expr[Unit] = '{
13871388
$out.writeArrayStart()
@@ -2600,7 +2601,7 @@ object JsonCodecMaker {
26002601
def cond(v: Expr[Array[_]])(using Quotes): Expr[Boolean] =
26012602
val da = d.asExprOf[Array[_]]
26022603
if (cfg.transientEmpty)
2603-
'{ $v.length > 0 && !${withEqualsFor(fTpe, v, da)((x1, x2) => genArrayEquals(fTpe, x1, x2))} }
2604+
'{ $v.length != 0 && !${withEqualsFor(fTpe, v, da)((x1, x2) => genArrayEquals(fTpe, x1, x2))} }
26042605
else
26052606
'{ !${withEqualsFor(fTpe, v, da)((x1, x2) => genArrayEquals(fTpe, x1, x2))} }
26062607

@@ -2618,7 +2619,7 @@ object JsonCodecMaker {
26182619
def cond(v: Expr[IArray[ft1]])(using Quotes): Expr[Boolean] =
26192620
val da = d.asExprOf[IArray[ft1]]
26202621
if (cfg.transientEmpty)
2621-
'{ $v.length > 0 && !${withEqualsFor(fTpe, v, da)((x1, x2) => genArrayEquals(fTpe, x1, x2))} }
2622+
'{ $v.length != 0 && !${withEqualsFor(fTpe, v, da)((x1, x2) => genArrayEquals(fTpe, x1, x2))} }
26222623
else
26232624
'{ !${withEqualsFor(fTpe, v, da)((x1, x2) => genArrayEquals(fTpe, x1, x2))} }
26242625

@@ -2662,7 +2663,7 @@ object JsonCodecMaker {
26622663
}
26632664
} else if (cfg.transientEmpty && fTpe <:< TypeRepr.of[Array[_]]) '{
26642665
val v = ${Select(x.asTerm, fieldInfo.getterOrField).asExprOf[ft & Array[_]]}
2665-
if (v.length > 0) {
2666+
if (v.length != 0) {
26662667
${genWriteConstantKey(fieldInfo.mappedName, out)}
26672668
${genWriteVal('v, fTpe :: types, fieldInfo.isStringified, None, out)}
26682669
}
@@ -2671,7 +2672,7 @@ object JsonCodecMaker {
26712672
fTpe1.asType match
26722673
case '[ft1] => '{
26732674
val v = ${Select(x.asTerm, fieldInfo.getterOrField).asExprOf[IArray[ft1]]}
2674-
if (v.length > 0) {
2675+
if (v.length != 0) {
26752676
${genWriteConstantKey(fieldInfo.mappedName, out)}
26762677
${genWriteVal('v, fTpe :: types, fieldInfo.isStringified, None, out)}
26772678
}

0 commit comments

Comments
 (0)