From 8f16160794a158b7fa73e5fa773f0075fc91542f Mon Sep 17 00:00:00 2001 From: OneWay Date: Sat, 7 Nov 2026 22:02:00 +0800 Subject: [PATCH] refactor(profile): simplify the generator code --- .../research/baselineprofile/BaselineProfileGenerator.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/baselineprofile/src/main/java/com/example/research/baselineprofile/BaselineProfileGenerator.kt b/baselineprofile/src/main/java/com/example/research/baselineprofile/BaselineProfileGenerator.kt index ce7090d..7cbb61e 100644 --- a/baselineprofile/src/main/java/com/example/research/baselineprofile/BaselineProfileGenerator.kt +++ b/baselineprofile/src/main/java/com/example/research/baselineprofile/BaselineProfileGenerator.kt @@ -186,8 +186,7 @@ class BaselineProfileGenerator { val fileName = device.executeShellCommand("ls $DOWNLOAD_DIR") .lineSequence() .map(String::trim) - .filter { it.endsWith(GZ_SUFFIX) } - .firstOrNull() + .firstOrNull { it.endsWith(GZ_SUFFIX) } ?: error("No $GZ_SUFFIX archives available in $DOWNLOAD_DIR") val archiveBytes = Base64.decode( device.executeShellCommand("base64 $DOWNLOAD_DIR/$fileName") @@ -208,7 +207,7 @@ class BaselineProfileGenerator { val headword = entry?.let(::firstHeadword).orEmpty() if (headword.isNotEmpty()) query = headword } else { - refTarget = refTarget ?: firstReference(line) + refTarget = firstReference(line) if (refTarget != null) break } } @@ -222,7 +221,7 @@ class BaselineProfileGenerator { } /** - * Extracts the plain target of the first [ref]...[/ref] pair on the line, + * Extracts the plain target of the first `[ref]...[/ref]` pair on the line, * dropping any nested DSL tags, so the scenario can follow a real * cross-reference instead of relying on a hardcoded word. */ @@ -307,7 +306,7 @@ class BaselineProfileGenerator { private companion object { val UTF8_BOM = byteArrayOf(0xEF.toByte(), 0xBB.toByte(), 0xBF.toByte()) val UTF16_BOM = byteArrayOf(0xFE.toByte(), 0xFF.toByte()) - val NESTED_TAG_REGEX = Regex("\\[[^\\]]*\\]") + val NESTED_TAG_REGEX = Regex("\\[[^]]*]") const val DOWNLOAD_DIR = "/sdcard/Download" const val GZ_SUFFIX = ".dsl.gz"