Optimizes memory use of the visual user and url tagger in new posts.

This commit is contained in:
Vitor Pamplona 2024-02-02 09:30:36 -05:00
parent d3d19b497b
commit 9d92976eb9
2 changed files with 6 additions and 14 deletions

View File

@ -615,7 +615,7 @@ open class Note(val idHex: String) {
// Regular Zap Receipts
zaps.forEach {
val noteEvent = it?.value?.event
val noteEvent = it.value?.event
if (noteEvent is LnZapEvent) {
sumOfAmounts += noteEvent.amount ?: BigDecimal.ZERO
}

View File

@ -56,11 +56,9 @@ fun buildAnnotatedStringWithUrlHighlighting(
val builderAfter = StringBuilder() // important to correctly measure Tag start and end
append(
text
.split('\n')
.map { paragraph: String ->
.split('\n').joinToString("\n") { paragraph: String ->
paragraph
.split(' ')
.map { word: String ->
.split(' ').joinToString(" ") { word: String ->
try {
if (word.startsWith("@npub") && word.length >= 64) {
val keyB32 = word.substring(0, 64)
@ -121,9 +119,7 @@ fun buildAnnotatedStringWithUrlHighlighting(
word
}
}
.joinToString(" ")
}
.joinToString("\n"),
},
)
substitutions.forEach {
@ -143,9 +139,7 @@ fun buildAnnotatedStringWithUrlHighlighting(
object : OffsetMapping {
override fun originalToTransformed(offset: Int): Int {
val inInsideRange =
substitutions
.filter { offset > it.original.start && offset < it.original.end }
.firstOrNull()
substitutions.firstOrNull { offset > it.original.start && offset < it.original.end }
if (inInsideRange != null) {
val percentInRange =
@ -165,9 +159,7 @@ fun buildAnnotatedStringWithUrlHighlighting(
override fun transformedToOriginal(offset: Int): Int {
val inInsideRange =
substitutions
.filter { offset > it.modified.start && offset < it.modified.end }
.firstOrNull()
substitutions.firstOrNull { offset > it.modified.start && offset < it.modified.end }
if (inInsideRange != null) {
val percentInRange =