Skip to content

Commit 78cc0e9

Browse files
committed
Text::CSV - optimize
1 parent ed0d0b6 commit 78cc0e9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/org/perlonjava/perlmodule/TextCsv.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.*;
1010

1111
import static org.perlonjava.runtime.RuntimeScalarCache.*;
12+
import static org.perlonjava.runtime.RuntimeScalarType.JAVAOBJECT;
1213

1314
/**
1415
* Text::CSV module implementation for PerlOnJava.
@@ -405,6 +406,11 @@ public static RuntimeList error_diag(RuntimeArray args, int ctx) {
405406
private static CSVFormat buildCSVFormat(RuntimeHash self) {
406407
CSVFormat.Builder builder = CSVFormat.DEFAULT.builder();
407408

409+
RuntimeScalar cached = self.get("_CSVFormat");
410+
if (cached.type == JAVAOBJECT) {
411+
return (CSVFormat) cached.value;
412+
}
413+
408414
// builder.setSkipHeaderRecord(false);
409415
// builder.setAllowMissingColumnNames(true);
410416

@@ -447,7 +453,9 @@ private static CSVFormat buildCSVFormat(RuntimeHash self) {
447453
builder.setRecordSeparator("");
448454
}
449455

450-
return builder.build();
456+
CSVFormat csvFormat = builder.build();
457+
cached.set(csvFormat); // Save in cache
458+
return csvFormat;
451459
}
452460

453461
/**

0 commit comments

Comments
 (0)