Skip to content

Commit

Permalink
Renamed key to safeKey where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Westcott committed Aug 12, 2015
1 parent b7884f8 commit 3796a55
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/fsharp/FSharp.Core/array.fs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ namespace Microsoft.FSharp.Collections

// Build the groupings
for v in array do
let key = projection v
let safeKey = projection v
let mutable prev = Unchecked.defaultof<_>
if dict.TryGetValue(key, &prev) then dict.[key] <- prev + 1 else dict.[key] <- 1
if dict.TryGetValue(safeKey, &prev) then dict.[safeKey] <- prev + 1 else dict.[safeKey] <- 1

let res = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked dict.Count
let mutable i = 0
Expand Down Expand Up @@ -435,13 +435,13 @@ namespace Microsoft.FSharp.Collections
// Build the groupings
for i = 0 to (array.Length - 1) do
let v = array.[i]
let key = keyf v
let safeKey = keyf v
let mutable prev = Unchecked.defaultof<_>
if dict.TryGetValue(key, &prev) then
if dict.TryGetValue(safeKey, &prev) then
prev.Add v
else
let prev = ResizeArray initialBucketSize
dict.[key] <- prev
dict.[safeKey] <- prev
prev.Add v

// Return the array-of-arrays.
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/FSharp.Core/fslib-extra-pervasives.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ module ExtraTopLevelOperators =
member s.Add(k,v) = raise (NotSupportedException(SR.GetString(SR.thisValueCannotBeMutated)))
member s.ContainsKey(k) = d.ContainsKey(makeSafeKey k)
member s.TryGetValue(k,r) =
let key = makeSafeKey k
if d.ContainsKey(key) then (r <- d.[key]; true) else false
let safeKey = makeSafeKey k
if d.ContainsKey(safeKey) then (r <- d.[safeKey]; true) else false
member s.Remove(k : 'Key) = (raise (NotSupportedException(SR.GetString(SR.thisValueCannotBeMutated))) : bool)
interface ICollection<KeyValuePair<'Key, 'T>> with
member s.Add(x) = raise (NotSupportedException(SR.GetString(SR.thisValueCannotBeMutated)));
Expand Down
10 changes: 5 additions & 5 deletions src/fsharp/FSharp.Core/list.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ namespace Microsoft.FSharp.Collections
match srcList with
| [] -> ()
| h::t ->
let key = projection h
let safeKey = projection h
let mutable prev = 0
if dict.TryGetValue(key, &prev) then dict.[key] <- prev + 1 else dict.[key] <- 1
if dict.TryGetValue(safeKey, &prev) then dict.[safeKey] <- prev + 1 else dict.[safeKey] <- 1
loop t
loop list
let mutable result = []
Expand Down Expand Up @@ -462,13 +462,13 @@ namespace Microsoft.FSharp.Collections
let rec loop list =
match list with
| v :: t ->
let key = keyf v
let safeKey = keyf v
let mutable prev = Unchecked.defaultof<_>
if dict.TryGetValue(key, &prev) then
if dict.TryGetValue(safeKey, &prev) then
prev.Add v
else
let prev = ResizeArray initialBucketSize
dict.[key] <- prev
dict.[safeKey] <- prev
prev.Add v
loop t
| _ -> ()
Expand Down
14 changes: 7 additions & 7 deletions src/fsharp/FSharp.Core/seq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,13 +1456,13 @@ namespace Microsoft.FSharp.Collections

// Build the groupings
seq |> iter (fun v ->
let key = keyf v
let safeKey = keyf v
let mutable prev = Unchecked.defaultof<_>
match dict.TryGetValue (key, &prev) with
match dict.TryGetValue (safeKey, &prev) with
| true -> prev.Add v
| false ->
let prev = ResizeArray minimumBucketSize
dict.[key] <- prev
dict.[safeKey] <- prev
prev.Add v)

// Trim the size of each result group, don't trim very small buckets, as excessive work, and garbage for
Expand Down Expand Up @@ -1548,11 +1548,11 @@ namespace Microsoft.FSharp.Collections

// Build the groupings
source |> iter (fun v ->
let key = keyf v
let safeKey = keyf v
let mutable prev = Unchecked.defaultof<_>
if dict.TryGetValue(key, &prev)
then dict.[key] <- prev + 1
else dict.[key] <- 1)
if dict.TryGetValue(safeKey, &prev)
then dict.[safeKey] <- prev + 1
else dict.[safeKey] <- 1)

dict |> map (fun group -> (getKey group.Key, group.Value))

Expand Down

0 comments on commit 3796a55

Please sign in to comment.