use Intl.Collator over String.prototype.localeCompare for better performance
This commit is contained in:
parent
c6c1e09cae
commit
d7a5547d80
11 changed files with 49 additions and 27 deletions
|
@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { memoize } from "lodash";
|
||||
|
||||
/**
|
||||
* Copy plaintext to user's clipboard
|
||||
* It will overwrite user's selection range
|
||||
|
@ -73,3 +75,14 @@ export function copyNode(ref: Element): boolean {
|
|||
selectText(ref);
|
||||
return document.execCommand('copy');
|
||||
}
|
||||
|
||||
|
||||
const collator = new Intl.Collator();
|
||||
/**
|
||||
* Performant language-sensitive string comparison
|
||||
* @param a the first string to compare
|
||||
* @param b the second string to compare
|
||||
*/
|
||||
export function compare(a: string, b: string): number {
|
||||
return collator.compare(a, b);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue