Skip to content

Commit

Permalink
Merge pull request #105 from RedMadRobot/profiling
Browse files Browse the repository at this point in the history
Fix performance issue
  • Loading branch information
taflanidi committed Apr 14, 2023
2 parents 55861f0 + 5a7039b commit 2f869d0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Source/InputMask/InputMask/Classes/View/UITextInput.swift
Expand Up @@ -58,7 +58,17 @@ public extension UITextInput {

let from: UITextPosition = position(from: beginningOfDocument, offset: newPosition)!
let to: UITextPosition = position(from: from, offset: 0)!
selectedTextRange = textRange(from: from, to: to)

let oldSelectedTextRange = selectedTextRange
let newSelectedTextRange = textRange(from: from, to: to)

if oldSelectedTextRange != newSelectedTextRange {
/**
Profiling shows that assigning a new `selectedTextRange` is a rather resources-consuming operation.
Thus this sub-optimisation to avoid performance hiccups.
*/
selectedTextRange = textRange(from: from, to: to)
}
}
}

Expand Down

0 comments on commit 2f869d0

Please sign in to comment.