Skip to content

Commit 2d7172b

Browse files
ncavealfonsogarciacaro
authored andcommitted
Removed _tail caching
1 parent f7e2e32 commit 2d7172b

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/Fable.Transforms/Fable2Babel.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ module Util =
12111211
let op = if nonEmpty then BinaryUnequal else BinaryEqual
12121212
upcast BinaryExpression(op, com.TransformAsExpr(ctx, expr), NullLiteral(), ?loc=range)
12131213
| Fable.ListTest nonEmpty ->
1214-
let expr = get range (com.TransformAsExpr(ctx, expr)) "empty"
1214+
let expr = get range (com.TransformAsExpr(ctx, expr)) "isEmpty"
12151215
if nonEmpty then upcast UnaryExpression(UnaryNot, expr, ?loc=range)
12161216
else expr
12171217
| Fable.UnionCaseTest(uci, ent) ->

src/fable-library/Types.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function compareList<T>(self: List<T>, other: List<T>) {
5656
}
5757
const idxDiff = self.idx - other.idx;
5858
for (let i = self.idx; i >= 0; i--) {
59-
let otherIdx = i - idxDiff;
59+
const otherIdx = i - idxDiff;
6060
if (otherIdx < 0) { return 1; }
6161
const selfItem = self.vals[i];
6262
const otherItem = other.vals[otherIdx];
@@ -73,7 +73,6 @@ export function newList<T>(head: T, tail: List<T>): List<T> {
7373
const vals = tail.vals.length === tail.idx + 1 ? tail.vals : tail.vals.slice(0, tail.idx + 1);
7474
vals.push(head);
7575
const li = new List(vals);
76-
li._tail = tail;
7776
return li;
7877
}
7978

@@ -92,7 +91,7 @@ export class List<T> implements IEquatable<List<T>>, IComparable<List<T>>, Itera
9291
this.idx = idx ?? this.vals.length - 1;
9392
}
9493

95-
public get empty() {
94+
public get isEmpty() {
9695
return this.idx < 0;
9796
}
9897

@@ -101,9 +100,7 @@ export class List<T> implements IEquatable<List<T>>, IComparable<List<T>>, Itera
101100
}
102101

103102
public get tail(): List<T> | undefined {
104-
return !this.empty
105-
? this._tail ?? (this._tail = new List(this.vals, this.idx - 1))
106-
: undefined;
103+
return this.idx >= 0 ? new List(this.vals, this.idx - 1) : undefined;
107104
}
108105

109106
public get length() {

0 commit comments

Comments
 (0)