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 // Regular Zap Receipts
zaps.forEach { zaps.forEach {
val noteEvent = it?.value?.event val noteEvent = it.value?.event
if (noteEvent is LnZapEvent) { if (noteEvent is LnZapEvent) {
sumOfAmounts += noteEvent.amount ?: BigDecimal.ZERO sumOfAmounts += noteEvent.amount ?: BigDecimal.ZERO
} }

View File

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