@@ -1875,8 +1875,9 @@ object JsonCodecMaker {
1875
1875
val paramVarNum = fields.size
1876
1876
val lastParamVarIndex = Math .max(0 , (paramVarNum - 1 ) >> 5 )
1877
1877
val lastParamVarBits = - 1 >>> - paramVarNum
1878
- val paramVars = (0 to lastParamVarIndex)
1879
- .map(i => ValDef (symbol(" p" + i, TypeRepr .of[Int ], Flags .Mutable ), Some (Literal (IntConstant {
1878
+ val paramVars =
1879
+ if (required.isEmpty && ! cfg.checkFieldDuplication) Nil
1880
+ else (0 to lastParamVarIndex).map(i => ValDef (symbol(" p" + i, TypeRepr .of[Int ], Flags .Mutable ), Some (Literal (IntConstant {
1880
1881
if (i == lastParamVarIndex) lastParamVarBits
1881
1882
else - 1
1882
1883
}))))
@@ -1951,17 +1952,19 @@ object JsonCodecMaker {
1951
1952
case ' [ft] =>
1952
1953
val tmpVar = Ref (tmpVars(fieldInfo.symbol.name).symbol)
1953
1954
val readVal = genReadVal(fTpe :: types, tmpVar.asExprOf[ft], fieldInfo.isStringified, false , in).asTerm
1954
- val n = Ref (paramVars(fieldInfo.nonTransientFieldIndex >> 5 ).symbol).asExprOf[Int ]
1955
- val m = Expr (1 << fieldInfo.nonTransientFieldIndex)
1956
- val nm = Expr (~ (1 << fieldInfo.nonTransientFieldIndex))
1957
1955
Block (List ({
1958
- if (cfg.checkFieldDuplication) {
1959
- ' {
1960
- if (($n & $m) != 0 ) $ {Assign (n.asTerm, ' { $n ^ $m }.asTerm).asExprOf[Unit ]}
1961
- else $in.duplicatedKeyError($l)
1962
- }.asTerm
1963
- } else if (required(fieldInfo.mappedName)) Assign (n.asTerm, ' { $n & $nm }.asTerm)
1964
- else ' { }.asTerm
1956
+ val isRequired = required(fieldInfo.mappedName)
1957
+ if (isRequired || cfg.checkFieldDuplication) {
1958
+ val n = Ref (paramVars(fieldInfo.nonTransientFieldIndex >> 5 ).symbol).asExprOf[Int ]
1959
+ val m = Expr (1 << fieldInfo.nonTransientFieldIndex)
1960
+ val nm = Expr (~ (1 << fieldInfo.nonTransientFieldIndex))
1961
+ if (cfg.checkFieldDuplication) {
1962
+ ' {
1963
+ if (($n & $m) != 0 ) $ {Assign (n.asTerm, ' { $n ^ $m }.asTerm).asExprOf[Unit ]}
1964
+ else $in.duplicatedKeyError($l)
1965
+ }.asTerm
1966
+ } else Assign (n.asTerm, ' { $n & $nm }.asTerm)
1967
+ } else ' { }.asTerm
1965
1968
}), Assign (tmpVar, readVal)).asExprOf[Unit ]
1966
1969
}
1967
1970
' {
0 commit comments