Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit781b410

Browse files
forkiKevinRansom
authored andcommitted
Optimize truncate for n = 0 (#5099)
Thanks for this.
1 parent5b4b633 commit781b410

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

‎src/fsharp/FSharp.Core/local.fs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,13 @@ module internal List =
756756
truncateToFreshConsTail cons2(count-1) t
757757

758758
lettruncate count list=
759-
match listwith
760-
|[]-> list
761-
|_::([]as nil)->if count>0then listelse nil
762-
| h::t->
763-
if count<=0then[]
764-
else
759+
if count<=0then
760+
[]
761+
else
762+
match listwith
763+
|[]
764+
|[_]-> list
765+
| h::t->
765766
letcons= freshConsNoTail h
766767
truncateToFreshConsTail cons(count-1) t
767768
cons

‎src/fsharp/FSharp.Core/seq.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@ namespace Microsoft.FSharp.Collections
852852
[<CompiledName("Truncate")>]
853853
lettruncate count(source:seq<'T>)=
854854
checkNonNull"source" source
855+
if count<=0then emptyelse
855856
seq{leti= ref0
856857
use ie= source.GetEnumerator()
857858
while!i< count&& ie.MoveNext()do

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp