Skip to content

Commit f609665

Browse files
committed
Improve performance for non urlMaximumLength users
1 parent f27a513 commit f609665

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

ActiveLabel/ActiveBuilder.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct ActiveBuilder {
2323
}
2424
}
2525

26-
static func createURLElements(from text: String, range: NSRange, maxChar: Int?) -> ([ElementTuple], String) {
26+
static func createURLElements(from text: String, range: NSRange, maximumLenght: Int?) -> ([ElementTuple], String) {
2727
let type = ActiveType.URL
2828
var text = text
2929
let matches = RegexParser.getElements(from: text, with: type.pattern, range: range)
@@ -34,14 +34,14 @@ struct ActiveBuilder {
3434
let word = nsstring.substringWithRange(match.range)
3535
.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
3636

37-
guard let maxChar = maxChar where word.characters.count > maxChar else {
38-
let newRange = (text as NSString).rangeOfString(word)
37+
guard let maxLenght = maximumLenght where word.characters.count > maxLenght else {
38+
let range = maximumLenght == nil ? match.range : (text as NSString).rangeOfString(word)
3939
let element = ActiveElement.create(with: type, text: word)
40-
elements.append((newRange, element, type))
40+
elements.append((range, element, type))
4141
continue
4242
}
4343

44-
let trimmedWord = word.trim(to: maxChar)
44+
let trimmedWord = word.trim(to: maxLenght)
4545
text = text.stringByReplacingOccurrencesOfString(word, withString: trimmedWord)
4646

4747
let newRange = (text as NSString).rangeOfString(trimmedWord)

ActiveLabel/ActiveLabel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ typealias ElementTuple = (range: NSRange, element: ActiveElement, type: ActiveTy
300300
var textRange = NSRange(location: 0, length: textLength)
301301

302302
if enabledTypes.contains(.URL) {
303-
let tuple = ActiveBuilder.createURLElements(from: textString, range: textRange, maxChar: urlMaximumLength)
303+
let tuple = ActiveBuilder.createURLElements(from: textString, range: textRange, maximumLenght: urlMaximumLength)
304304
let urlElements = tuple.0
305305
let finalText = tuple.1
306306
textString = finalText

0 commit comments

Comments
 (0)