Conversation
Just adds a method to StringBuilder. Signed-off-by: Mike Samuel <mikesamuel@gmail.com>
Signed-off-by: Mike Samuel <mikesamuel@gmail.com>
| } | ||
| val JavaLang.stringBuilderClear by receiver { | ||
| inlineSupport("StringBuilder::clear", arity = 1, needsSelf = true) { pos, args -> | ||
| args[0].method("setLength", J.IntegerLiteral(pos.rightEdge, 0), pos = pos) |
There was a problem hiding this comment.
Strangely, Java's StringBuilder does not have a clear method but C# and Rust do.
There was a problem hiding this comment.
Strangely, Java's StringBuilder does not have a clear method but C# and Rust do.
Interesting. Not sure what I'd have guessed on that. (Since I forget a lot.)
| stringBuilder ?: Js.Identifier(sbPos, JsIdentifierName("stringBuilder"), null), | ||
| Js.NumericLiteral(sbPos.rightEdge, 0), | ||
| computed = true, | ||
| voidExpr( |
There was a problem hiding this comment.
Putting void in front of an idiom is cheap and avoids leaking values.
There was a problem hiding this comment.
Putting
voidin front of an idiom is cheap and avoids leaking values.
I'll try to remember.
Signed-off-by: Mike Samuel <mikesamuel@gmail.com>
| } | ||
| val JavaLang.stringBuilderClear by receiver { | ||
| inlineSupport("StringBuilder::clear", arity = 1, needsSelf = true) { pos, args -> | ||
| args[0].method("setLength", J.IntegerLiteral(pos.rightEdge, 0), pos = pos) |
There was a problem hiding this comment.
Strangely, Java's StringBuilder does not have a clear method but C# and Rust do.
Interesting. Not sure what I'd have guessed on that. (Since I forget a lot.)
| stringBuilder ?: Js.Identifier(sbPos, JsIdentifierName("stringBuilder"), null), | ||
| Js.NumericLiteral(sbPos.rightEdge, 0), | ||
| computed = true, | ||
| voidExpr( |
There was a problem hiding this comment.
Putting
voidin front of an idiom is cheap and avoids leaking values.
I'll try to remember.
| while #builder ~= 0 do | ||
| builder[#builder] = nil | ||
| end | ||
| end |
There was a problem hiding this comment.
Lua still often surprises me.
Just adds a method to StringBuilder.