Skip to content

Commit 7d3cd5a

Browse files
committed
scalar - switch optimization
1 parent fb56664 commit 7d3cd5a

File tree

1 file changed

+5
-31
lines changed

1 file changed

+5
-31
lines changed

src/main/java/org/perlonjava/runtime/RuntimeScalar.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,7 @@ public int getInt() {
238238
case GLOB -> 1; // Assuming globs are truthy, so 1
239239
case REGEX -> 1; // Assuming regexes are truthy, so 1
240240
case JAVAOBJECT -> value != null ? 1 : 0;
241-
default -> {
242-
if ((type & REFERENCE_BIT) != 0) {
243-
yield Overload.numify(this).getInt();
244-
}
245-
yield ((RuntimeScalarReference) value).getIntRef();
246-
}
241+
default -> Overload.numify(this).getInt();
247242
};
248243
}
249244

@@ -259,12 +254,7 @@ public long getLong() {
259254
case GLOB -> 1L;
260255
case REGEX -> 1L;
261256
case JAVAOBJECT -> value != null ? 1L : 0L;
262-
default -> {
263-
if ((type & REFERENCE_BIT) != 0) {
264-
yield Overload.numify(this).getLong();
265-
}
266-
yield ((RuntimeScalarReference) value).getIntRef();
267-
}
257+
default -> Overload.numify(this).getLong();
268258
};
269259
}
270260

@@ -280,12 +270,7 @@ public double getDouble() {
280270
case GLOB -> 1.0;
281271
case REGEX -> 1.0;
282272
case JAVAOBJECT -> value != null ? 1.0 : 0.0;
283-
default -> {
284-
if ((type & REFERENCE_BIT) != 0) {
285-
yield Overload.numify(this).getDouble();
286-
}
287-
yield ((RuntimeScalarReference) value).getDoubleRef();
288-
}
273+
default -> Overload.numify(this).getDouble();
289274
};
290275
}
291276

@@ -304,13 +289,7 @@ public boolean getBoolean() {
304289
case GLOB -> true;
305290
case REGEX -> true;
306291
case JAVAOBJECT -> value != null;
307-
default -> {
308-
// All reference types
309-
if ((type & REFERENCE_BIT) != 0) {
310-
yield Overload.boolify(this).getBoolean();
311-
}
312-
yield ((RuntimeScalarReference) value).getBooleanRef();
313-
}
292+
default -> Overload.boolify(this).getBoolean();
314293
};
315294
}
316295

@@ -418,12 +397,7 @@ public String toString() {
418397
case GLOB -> value == null ? "" : value.toString();
419398
case REGEX -> value.toString();
420399
case JAVAOBJECT -> value.toString();
421-
default -> {
422-
if ((type & REFERENCE_BIT) != 0) {
423-
yield Overload.stringify(this).toString();
424-
}
425-
yield ((RuntimeScalarReference) value).toStringRef();
426-
}
400+
default -> Overload.stringify(this).toString();
427401
};
428402
}
429403

0 commit comments

Comments
 (0)