Skip to content

Commit 42a1391

Browse files
authored
Merge pull request rarestype#123 from rarestype/internalize-exp10
[patch]: internalize and colocate the exp10 table with the module that actually uses it
2 parents c366b48 + cc90733 commit 42a1391

4 files changed

Lines changed: 43 additions & 49 deletions

File tree

Sources/JSONAST/JSON.Number.Base10.Inverse.swift

Lines changed: 0 additions & 41 deletions
This file was deleted.

Sources/JSONAST/JSON.Number.Base10.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
extension JSON.Number {
2-
/// A namespace for decimal-related functionality.
3-
///
4-
/// This API is used by library functions that are emitted into the client.
5-
/// Most library users should not have to call it directly.
6-
public enum Base10 {
7-
/// Positive powers of 10, up to `10_000_000_000_000_000_000`.
2+
@available(
3+
*, deprecated, message: """
4+
JSON.Number.Base10 is deprecated and will be removed in a future release
5+
"""
6+
) public enum Base10 {
87
public static let Exp: [UInt64] = [
98
1,
109
10,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
extension JSON.Number {
2+
/// A namespace for decimal-related functionality.
3+
enum Exp10 {}
4+
}
5+
extension JSON.Number.Exp10 {
6+
static var startIndex: Int { 0 }
7+
static var endIndex: Int { 20 }
8+
9+
static subscript(power: Int) -> UInt64 {
10+
switch power {
11+
case 0: 1
12+
case 1: 10
13+
case 2: 100
14+
case 3: 1_000
15+
case 4: 10_000
16+
case 5: 100_000
17+
case 6: 1_000_000
18+
case 7: 10_000_000
19+
case 8: 100_000_000
20+
case 9: 1_000_000_000
21+
case 10: 10_000_000_000
22+
case 11: 100_000_000_000
23+
case 12: 1_000_000_000_000
24+
case 13: 10_000_000_000_000
25+
case 14: 100_000_000_000_000
26+
case 15: 1_000_000_000_000_000
27+
case 16: 10_000_000_000_000_000
28+
case 17: 100_000_000_000_000_000
29+
case 18: 1_000_000_000_000_000_000
30+
case 19: 10_000_000_000_000_000_000
31+
default: fatalError("power out of representable range")
32+
// UInt64.max:
33+
// 18_446_744_073_709_551_615
34+
}
35+
}
36+
}

Sources/JSONParsing/Rules/JSON.NumberRule.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ extension JSON.NumberRule: ParsingRule {
119119
places = 0
120120
}
121121

122-
if shift < JSON.Number.Base10.Exp.endIndex,
122+
if shift < JSON.Number.Exp10.endIndex,
123123
case (let shifted, false) = units.multipliedReportingOverflow(
124-
by: JSON.Number.Base10.Exp[shift]
124+
by: JSON.Number.Exp10[shift]
125125
) {
126126
units = shifted
127127
} else {

0 commit comments

Comments
 (0)