perf: don't use regex in trim_{prefix,suffix}
regex is overkill for this, and performance is quite bad
Fixes: b131c74ee3 ("Add prefix and suffix string trimming functions")
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -257,12 +257,20 @@ func mention_str(_ m: Mention<MentionRef>, profiles: Profiles) -> CompatibleText
|
||||
|
||||
// trim suffix whitespace and newlines
|
||||
func trim_suffix(_ str: String) -> String {
|
||||
return str.replacingOccurrences(of: "\\s+$", with: "", options: .regularExpression)
|
||||
var result = str
|
||||
while result.last?.isWhitespace == true {
|
||||
result.removeLast()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// trim prefix whitespace and newlines
|
||||
func trim_prefix(_ str: String) -> String {
|
||||
return str.replacingOccurrences(of: "^\\s+", with: "", options: .regularExpression)
|
||||
var result = str
|
||||
while result.first?.isWhitespace == true {
|
||||
result.removeFirst()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
struct LongformContent {
|
||||
|
||||
Reference in New Issue
Block a user