Skip to content

Commit

Permalink
Improve performance for non urlMaximumLength users
Browse files Browse the repository at this point in the history
  • Loading branch information
polqf committed Sep 5, 2016
1 parent f27a513 commit f609665
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions ActiveLabel/ActiveBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct ActiveBuilder {
}
}

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

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

let trimmedWord = word.trim(to: maxChar)
let trimmedWord = word.trim(to: maxLenght)
text = text.stringByReplacingOccurrencesOfString(word, withString: trimmedWord)

let newRange = (text as NSString).rangeOfString(trimmedWord)
Expand Down
2 changes: 1 addition & 1 deletion ActiveLabel/ActiveLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ typealias ElementTuple = (range: NSRange, element: ActiveElement, type: ActiveTy
var textRange = NSRange(location: 0, length: textLength)

if enabledTypes.contains(.URL) {
let tuple = ActiveBuilder.createURLElements(from: textString, range: textRange, maxChar: urlMaximumLength)
let tuple = ActiveBuilder.createURLElements(from: textString, range: textRange, maximumLenght: urlMaximumLength)
let urlElements = tuple.0
let finalText = tuple.1
textString = finalText
Expand Down

0 comments on commit f609665

Please sign in to comment.