Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions sjsonnet/src/sjsonnet/stdlib/SetModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,27 @@ object SetModule extends AbstractFunctionModule {
val out = new mutable.ArrayBuilder.ofRef[Lazy]
// Set a reasonable size hint - in the worst case (no duplicates), we'll need arrValue.length elements
out.sizeHint(arrValue.length)
var last: Lazy = null
var knownSize = 0
for (v <- arrValue) {
val outResult = out.result()
if (outResult.length == 0) {
if (knownSize == 0) {
out.+=(v)
last = v
knownSize += 1
} else if (keyF.isInstanceOf[Val.False]) {
if (!ev.equal(outResult.last.force, v.force)) {
if (!ev.equal(last.force, v.force)) {
out.+=(v)
last = v
knownSize += 1
}
} else if (!keyF.isInstanceOf[Val.False]) {
} else {
val keyFFunc = keyF.asInstanceOf[Val.Func]
val o1Key = keyFFunc.apply1(v, pos.noOffset)(ev, TailstrictModeDisabled)
val o2Key = keyFFunc.apply1(outResult.last, pos.noOffset)(ev, TailstrictModeDisabled)
val o2Key = keyFFunc.apply1(last, pos.noOffset)(ev, TailstrictModeDisabled)
if (!ev.equal(o1Key, o2Key)) {
out.+=(v)
last = v
knownSize += 1
}
}
}
Expand Down