From 568b7d6afb43d7f501d1baf14d5a10470541bba2 Mon Sep 17 00:00:00 2001 From: Behnam Mohammadi Date: Tue, 10 Nov 2020 02:13:44 +0330 Subject: refactor(std/fs): improve performance by using some instead filter method (#8322) --- std/fs/eol.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'std') diff --git a/std/fs/eol.ts b/std/fs/eol.ts index 2f15be269..5ea554c6e 100644 --- a/std/fs/eol.ts +++ b/std/fs/eol.ts @@ -17,12 +17,9 @@ export function detect(content: string): EOL | null { if (!d || d.length === 0) { return null; } - const crlf = d.filter((x: string): boolean => x === EOL.CRLF); - if (crlf.length > 0) { - return EOL.CRLF; - } else { - return EOL.LF; - } + const hasCRLF = d.some((x: string): boolean => x === EOL.CRLF); + + return hasCRLF ? EOL.CRLF : EOL.LF; } /** Format the file to the targeted EOL */ -- cgit v1.2.3