Skip to content

Commit

Permalink
[Lib] Improve performance of ToNList().
Browse files Browse the repository at this point in the history
  • Loading branch information
VladD2 committed Jul 16, 2012
1 parent 756e9e1 commit a80ecf8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
17 changes: 16 additions & 1 deletion lib/Nemerle.Collections.n
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,24 @@ namespace Nemerle.Collections
ToNList (source)
}

public ToNList[T](this source : SCG.List[T]) : list[T] { NToList(source) }

public NToList[T](this source : SCG.List[T]) : list[T]
{
def loop(index, acc) : list[T]
{
if (index >= 0)
loop(index - 1, source[index] :: acc)
else
acc
}

loop(source.Count - 1, [])
}

public NToList[T](this source : Seq[T]) : list[T]
{
NList.ToList(source)
NToList(SCG.List(source))
}

/// Convert collection to array.
Expand Down
9 changes: 5 additions & 4 deletions lib/list.n
Original file line number Diff line number Diff line change
Expand Up @@ -708,15 +708,16 @@ namespace Nemerle.Collections
/**
* Converts an array into a list.
*/
public FromArray [T] ([NotNull] x : array [T]) : list [T] {
def loop (index, acc) : list [T] {
public FromArray [T] ([NotNull] source : array [T]) : list [T] {
def loop(index, acc) : list[T]
{
if (index >= 0)
loop (index - 1, x [index] :: acc)
loop(index - 1, source[index] :: acc)
else
acc
}

loop (x.Length - 1, [])
loop(source.Length - 1, [])
}

public ToListRev[T] ([NotNull] this seq : SCG.IEnumerable [T]) : list [T]
Expand Down

0 comments on commit a80ecf8

Please sign in to comment.