Here's the getter/setter for what I'm talking about.
|
public subscript(of roll: Roll) -> Chance { |
|
get { |
|
return chances[roll] ?? Chance.zero |
|
} |
|
set { |
|
chances[roll] = newValue |
|
} |
|
} |
As you can see, when getting a
Chance, the assumption is that if it is not there, it's zero. That's what we want. However, when we
set a chance
to zero, we add it to the dictionary, potentially resulting in a large number of entries with
Chance.zero as their values. This is unnecessary, could potentially be detrimental (storage space), and is internally inconsistent. I think it doesn't actually have an outward-facing effect, because we filter out chances that are not greater than zero:
|
for (roll, chance) in chances where chance.n > 0 { |
but we could and probably should still change this.
Here's the getter/setter for what I'm talking about.
DiceKit/Sources/DiceKit/Chances.swift
Lines 52 to 59 in d67f52f
As you can see, when getting a
Chance, the assumption is that if it is not there, it's zero. That's what we want. However, when we set a chance to zero, we add it to the dictionary, potentially resulting in a large number of entries withChance.zeroas their values. This is unnecessary, could potentially be detrimental (storage space), and is internally inconsistent. I think it doesn't actually have an outward-facing effect, because we filter out chances that are not greater than zero:DiceKit/Sources/DiceKit/Chances.swift
Line 27 in d67f52f
but we could and probably should still change this.