Skip to content

Commit 640f6e2

Browse files
committed
.
1 parent 2f168f6 commit 640f6e2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sjsonnet/src/sjsonnet/stdlib/StringModule.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,16 @@ object StringModule extends AbstractFunctionModule {
314314
}
315315

316316
private object EncodeUTF8 extends Val.Builtin1("encodeUTF8", "str") {
317-
def evalRhs(s: Lazy, ev: EvalScope, pos: Position): Val =
318-
Val.Arr(pos, s.force.asString.getBytes(UTF_8).map(i => Val.Num(pos, i & 0xff)))
317+
def evalRhs(s: Lazy, ev: EvalScope, pos: Position): Val = {
318+
val bytes = s.force.asString.getBytes(UTF_8)
319+
val arr = new Array[Lazy](bytes.length)
320+
var i = 0
321+
while (i < bytes.length) {
322+
arr(i) = Val.Num(pos, bytes(i) & 0xff)
323+
i += 1
324+
}
325+
Val.Arr(pos, arr)
326+
}
319327
}
320328

321329
private object DecodeUTF8 extends Val.Builtin1("decodeUTF8", "arr") {

0 commit comments

Comments
 (0)