Skip to content

Commit 3abaf71

Browse files
committed
Reuse existing XML parser instance
1 parent b7ed97f commit 3abaf71

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/src/net/alphadev/opml/exporter/OpmlFileFormatter.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import nl.adaptivity.xmlutil.serialization.XML
55

66
private const val INDENT_SIZE = 4
77

8-
fun formatOpmlFile(opmlFile: OpmlFile): String? = try {
8+
private val xml by lazy {
99
XML {
1010
indent = INDENT_SIZE
11-
}.encodeToString(OpmlFile.serializer(), opmlFile) + "\n"
11+
}
12+
}
13+
14+
fun formatOpmlFile(opmlFile: OpmlFile): String? = try {
15+
xml.encodeToString(OpmlFile.serializer(), opmlFile) + "\n"
1216
} catch (_: Throwable) {
1317
null
1418
}

lib/src/net/alphadev/opml/import/OpmlFileParser.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import kotlinx.serialization.decodeFromString
44
import net.alphadev.opml.format.OpmlFile
55
import nl.adaptivity.xmlutil.serialization.XML
66

7+
private val xml by lazy {
8+
XML()
9+
}
10+
711
fun parseOpmlFile(input: String): OpmlFile? = try {
8-
XML().decodeFromString<OpmlFile>(input)
12+
xml.decodeFromString<OpmlFile>(input)
913
} catch (_: Throwable) {
1014
null
1115
}

0 commit comments

Comments
 (0)