Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
## 2024-05-18 - Pre-compile Regex in VoiceInputManager
**Learning:** `VoiceInputManager.syncRecognizedText` instantiates `Regex("[,.?!;:]")` inside a frequent method call, increasing allocation pressure on voice typing hot paths.
**Action:** Extract repeated `Regex` instantiations in input hot paths (such as `syncRecognizedText`) into companion object private constants to reduce memory allocation and compilation overhead.
## 2024-05-18 - Pre-compile Regex in OCR formatting
**Learning:** `OcrTextFormatter.formatLines` instantiated `Regex` for bullet removal inline every time it was called when `stripBullets` was true. This causes unnecessary allocation and compilation overhead when parsing OCR lines.
**Action:** Extract frequently used formatting regexes (such as `bulletRegex`) into `object` or companion object private constants (`private val BULLET_REGEX`) to optimize regex reuse and eliminate unnecessary compilation per text parsing operation.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import java.util.Locale

object OcrTextFormatter {

private val BULLET_REGEX = Regex("""^(\s*[-*‒–—►β–ͺβ–«]|\[[ xX]?\]|\d+[\.\)]|[a-zA-Z][\.\)])\s*""")

fun format(context: Context, rawLines: List<String>): List<String> {
val prefs = context.prefs()
val keepLineBreaks = prefs.getBoolean(OcrPluginLoader.PREF_OCR_KEEP_LINE_BREAKS, true)
Expand Down Expand Up @@ -51,8 +53,7 @@ object OcrTextFormatter {
}
}
if (stripBullets) {
val bulletRegex = Regex("""^(\s*[-*‒–—►β–ͺβ–«]|\[[ xX]?\]|\d+[\.\)]|[a-zA-Z][\.\)])\s*""")
lines = lines.map { it.replace(bulletRegex, "") }
lines = lines.map { it.replace(BULLET_REGEX, "") }
}
if (trimWhitespace) {
lines = lines.map { it.trim() }.filter { it.isNotEmpty() }
Expand Down
Loading