Skip to content
Snippets Groups Projects
Commit 0c3ae0f8 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Preformance improvements

parent c7d3208a
Branches
Tags
No related merge requests found
...@@ -22,7 +22,6 @@ package de.kuschku.quasseldroid.util.irc.format ...@@ -22,7 +22,6 @@ package de.kuschku.quasseldroid.util.irc.format
import android.content.Context import android.content.Context
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import de.kuschku.quasseldroid.R import de.kuschku.quasseldroid.R
import de.kuschku.quasseldroid.util.compatibility.AndroidCrashFixer
import de.kuschku.quasseldroid.util.helper.getColorCompat import de.kuschku.quasseldroid.util.helper.getColorCompat
import de.kuschku.quasseldroid.util.irc.format.model.FormatDescription import de.kuschku.quasseldroid.util.irc.format.model.FormatDescription
import de.kuschku.quasseldroid.util.irc.format.model.FormatInfo import de.kuschku.quasseldroid.util.irc.format.model.FormatInfo
...@@ -71,11 +70,9 @@ class IrcFormatDeserializer(private val mircColors: IntArray) { ...@@ -71,11 +70,9 @@ class IrcFormatDeserializer(private val mircColors: IntArray) {
* @param content mIRC formatted String * @param content mIRC formatted String
* @return a CharSequence with Android’s span format representing the input string * @return a CharSequence with Android’s span format representing the input string
*/ */
fun formatString(content: String?, colorize: Boolean, fun formatString(str: String?, colorize: Boolean,
output: MutableList<FormatInfo>? = null): CharSequence { output: MutableList<FormatInfo>? = null): CharSequence {
if (content == null) return "" if (str == null) return ""
val str = AndroidCrashFixer.removeCrashableCharacters(content)
val plainText = SpannableStringBuilder() val plainText = SpannableStringBuilder()
var bold: FormatDescription<IrcFormat.Bold>? = null var bold: FormatDescription<IrcFormat.Bold>? = null
...@@ -371,12 +368,14 @@ class IrcFormatDeserializer(private val mircColors: IntArray) { ...@@ -371,12 +368,14 @@ class IrcFormatDeserializer(private val mircColors: IntArray) {
* @return Index of first character that is not a digit * @return Index of first character that is not a digit
*/ */
private fun findEndOfNumber(str: String, start: Int): Int { private fun findEndOfNumber(str: String, start: Int): Int {
val validCharCodes = setOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
val searchFrame = str.substring(start) val searchFrame = str.substring(start)
var i = 0 var i = 0
while (i < 2 && i < searchFrame.length) { loop@ while (i < 2 && i < searchFrame.length) {
if (!validCharCodes.contains(searchFrame[i])) { when (searchFrame[i]) {
break '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' -> {
// Do nothing
}
else -> break@loop
} }
i++ i++
} }
...@@ -389,15 +388,15 @@ class IrcFormatDeserializer(private val mircColors: IntArray) { ...@@ -389,15 +388,15 @@ class IrcFormatDeserializer(private val mircColors: IntArray) {
* @return Index of first character that is not a digit * @return Index of first character that is not a digit
*/ */
private fun findEndOfHexNumber(str: String, start: Int): Int { private fun findEndOfHexNumber(str: String, start: Int): Int {
val validCharCodes = setOf(
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'a', 'b',
'c', 'd', 'e', 'f'
)
val searchFrame = str.substring(start) val searchFrame = str.substring(start)
var i = 0 var i = 0
while (i < 6 && i < searchFrame.length) { loop@ while (i < 6 && i < searchFrame.length) {
if (!validCharCodes.contains(searchFrame[i])) { when (searchFrame[i]) {
break '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'a', 'b',
'c', 'd', 'e', 'f' -> {
// Do nothing
}
else -> break@loop
} }
i++ i++
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment