diff options
author | Vsevolod Tolstopyatov <qwwdfsad@gmail.com> | 2023-03-08 21:02:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-08 21:02:57 +0300 |
commit | 6b46d95bf31a15952c07e8072bc134bbbf02ca5f (patch) | |
tree | 4002eb8da5171e0ee11bb2f14b6dfa8aa0bdaa08 | |
parent | 14c05d70b52814fe48e930b3f61fed5e8586718c (diff) | |
download | dokka-6b46d95bf31a15952c07e8072bc134bbbf02ca5f.tar.gz dokka-6b46d95bf31a15952c07e8072bc134bbbf02ca5f.tar.bz2 dokka-6b46d95bf31a15952c07e8072bc134bbbf02ca5f.zip |
Improve performance of 'parseWithNormalisedSpaces' that is unconditionally invoked for each HTML text element (#2730)
Addresses #2729
-rw-r--r-- | plugins/base/src/main/kotlin/translators/parseWithNormalisedSpaces.kt | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/plugins/base/src/main/kotlin/translators/parseWithNormalisedSpaces.kt b/plugins/base/src/main/kotlin/translators/parseWithNormalisedSpaces.kt index 4bb60f1a..7bda9d0b 100644 --- a/plugins/base/src/main/kotlin/translators/parseWithNormalisedSpaces.kt +++ b/plugins/base/src/main/kotlin/translators/parseWithNormalisedSpaces.kt @@ -44,7 +44,13 @@ internal fun String.parseHtmlEncodedWithNormalisedSpaces( */ internal fun String.parseWithNormalisedSpaces( renderWhiteCharactersAsSpaces: Boolean -): List<DocTag> = - //parsing it using jsoup is required to get codePoints, otherwise they are interpreted separately, as chars - //But we dont need to do it for java as it is already parsed with jsoup - Jsoup.parseBodyFragment(this).body().wholeText().parseHtmlEncodedWithNormalisedSpaces(renderWhiteCharactersAsSpaces)
\ No newline at end of file +): List<DocTag> { + if (!requiresHtmlEncoding()) { + return parseHtmlEncodedWithNormalisedSpaces(renderWhiteCharactersAsSpaces) + } + // parsing it using jsoup is required to get codePoints, otherwise they are interpreted separately, as chars + // But we dont need to do it for java as it is already parsed with jsoup + return Jsoup.parseBodyFragment(this).body().wholeText().parseHtmlEncodedWithNormalisedSpaces(renderWhiteCharactersAsSpaces) +} + +private fun String.requiresHtmlEncoding(): Boolean = indexOf('&') != -1 |