X Tutup
Skip to content

Commit 437cd06

Browse files
committed
Take allocation out of GRNumberPrinter integer printing
- fixes SeasideSt#66
1 parent 19077c8 commit 437cd06

File tree

20 files changed

+183
-118
lines changed

20 files changed

+183
-118
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
utilities
2+
lengthOf: aNumber base: aBaseInteger
3+
"Answer the number of digits of aNumber in the base aBaseInteger.
4+
Same as #decimalDigitLength"
5+
6+
| integer current length |
7+
integer := aNumber truncated abs.
8+
length := 1.
9+
current := aBaseInteger.
10+
[ current <= integer ] whileTrue: [
11+
length := length + 1.
12+
current := current * aBaseInteger ].
13+
^ length
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
utilities
2+
padLeft: aCharacter to: aPadCountInteger on: aStream
3+
"Pad to the left side of aString with aCharacter to at anInteger characters."
4+
5+
1 to: aPadCountInteger do: [ :index |
6+
separator isNil ifFalse: [
7+
(index ~= 1 and: [ (digits - index) \\ 3 = 2 ])
8+
ifTrue: [ aStream nextPut: separator ] ].
9+
aStream nextPut: aCharacter ]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
utilities
2+
printDigitsOf: aNumber withLength: aLengthInteger on: aStream
3+
"Print the digits of aNumber with a lenght of aLengthInteger on aStream.
4+
Also print a separator if required."
5+
6+
| rest |
7+
rest := aNumber truncated abs.
8+
1 to: aLengthInteger do: [ :index |
9+
| divisor current |
10+
divisor := base raisedTo: aLengthInteger - index.
11+
current := rest // divisor.
12+
separator isNil ifFalse: [
13+
(index ~= 1 and: [ (aLengthInteger - index) \\ 3 = 2 ])
14+
ifTrue: [ aStream nextPut: separator ] ].
15+
aStream nextPut: (characters at: current + 1).
16+
rest := rest - (divisor * current) ]

repository/Grease-Core.package/GRNumberPrinter.class/instance/printFraction.on..st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ printFraction: aNumber on: aStream
55
pad: (self digitsOf: aNumber rounded base: base)
66
left: $0 to: precision.
77
separator isNil
8-
ifFalse: [ result := self separate: result left: separator ].
9-
aStream nextPutAll: result
8+
ifTrue: [ aStream nextPutAll: result ]
9+
ifFalse: [ self separate: result left: separator on: aStream ]
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
printing
22
printInteger: aNumber on: aStream
3-
| result |
4-
result := self digitsOf: aNumber integerPart base: base.
5-
separator isNil
6-
ifFalse: [ result := self separate: result right: separator ].
7-
(digits isNil or: [ padding isNil ])
8-
ifFalse: [ result := self pad: result left: padding to: digits ].
9-
aStream nextPutAll: result
3+
| length |
4+
length := self lengthOf: aNumber base: base.
5+
6+
(digits notNil and: [ padding notNil ])
7+
ifTrue: [ self padLeft: padding to: (digits - length) on: aStream ].
8+
9+
self printDigitsOf: aNumber withLength: length on: aStream

repository/Grease-Core.package/GRNumberPrinter.class/instance/separate.left..st

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
utilities
2+
separate: aString left: aCharacter on: aStream
3+
"Separate from the left side every 3 characters with aCharacter."
4+
5+
| size |
6+
size := aString size.
7+
1 to: size do: [ :index |
8+
(index ~= 1 and: [ index \\ 3 = 1 ])
9+
ifTrue: [ aStream nextPut: aCharacter ].
10+
aStream nextPut: (aString at: index) ]

repository/Grease-Core.package/GRNumberPrinter.class/methodProperties.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
{
22
"instance" : {
3+
"printInteger:on:" : "pmm 9/9/2018 14:50",
34
"separator:" : "lr 7/24/2008 14:35",
45
"initialize" : "lr 2/6/2010 10:58",
56
"precision:" : "lr 7/25/2008 19:16",
67
"printFloat:on:" : "pmm 9/15/2013 11:45",
78
"delimiter:" : "lr 7/24/2008 14:36",
89
"padding:" : "lr 7/24/2008 11:51",
9-
"printFraction:on:" : "lr 6/4/2009 21:41",
10+
"printFraction:on:" : "pmm 9/9/2018 11:31",
1011
"infinite:" : "lr 3/24/2008 16:19",
12+
"separate:left:on:" : "pmm 9/9/2018 11:30",
1113
"separate:right:" : "lr 7/24/2008 14:34",
1214
"uppercase" : "lr 2/6/2010 10:17",
1315
"lowercase" : "lr 2/6/2010 10:17",
16+
"lengthOf:base:" : "pmm 9/9/2018 15:08",
1417
"printNaN:on:" : "lr 3/24/2008 16:39",
18+
"padLeft:to:on:" : "pmm 9/9/2018 14:32",
1519
"characters:" : "lr 2/6/2010 10:17",
1620
"nan:" : "lr 3/24/2008 16:19",
1721
"base:" : "lr 7/25/2008 19:16",
1822
"digitsOf:base:" : "lr 5/13/2010 12:26",
19-
"separate:left:" : "lr 7/24/2008 14:34",
2023
"accuracy:" : "lr 7/25/2008 19:13",
21-
"print:on:" : "lr 3/24/2008 16:27",
24+
"printDigitsOf:withLength:on:" : "pmm 9/9/2018 15:10",
2225
"digits:" : "lr 7/24/2008 11:50",
23-
"printInfinite:on:" : "lr 3/24/2008 16:39",
24-
"printInteger:on:" : "lr 7/24/2008 12:39"
26+
"print:on:" : "lr 3/24/2008 16:27",
27+
"printInfinite:on:" : "lr 3/24/2008 16:39"
2528
},
2629
"class" : {
2730
"initialize" : "lr 1/23/2009 21:18"
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
{
2-
"class" : {
3-
"grPackages" : "JohanBrichau 12/15/2013 18:27",
4-
"greaseCore" : "pmm 9/12/2013 16:00" },
52
"instance" : {
6-
"addDependenciesTo:" : "lr 9/5/2009 18:35",
7-
"addDependency:" : "merged 10/20/2008 09:33",
8-
"allDependencies" : "lr 2/17/2010 15:18",
93
"dependencies" : "jf 3/15/2009 17:00",
10-
"description" : "merged 10/20/2008 09:23",
11-
"description:" : "lr 10/25/2009 11:26",
12-
"greaseUrl" : "pmm 9/12/2013 15:57",
4+
"license:" : "obi 10/8/2009 07:51",
135
"initialize" : "lr 2/17/2010 15:06",
14-
"isLGPL" : "lr 10/25/2009 15:19",
15-
"isMIT" : "lr 10/25/2009 15:19",
166
"license" : "lr 2/10/2010 11:18",
17-
"license:" : "obi 10/8/2009 07:51",
187
"name" : "lr 2/17/2010 15:18",
8+
"description:" : "lr 10/25/2009 11:26",
9+
"seasideUrl" : "pmm 9/12/2013 15:58",
10+
"allDependencies" : "lr 2/17/2010 15:18",
11+
"isLGPL" : "lr 10/25/2009 15:19",
12+
"seasideLGPLUrl" : "pmm 9/12/2013 15:59",
13+
"greaseUrl" : "pmm 9/12/2013 15:57",
1914
"name:" : "lr 10/25/2009 11:26",
20-
"printOn:" : "merged 10/20/2008 09:24",
21-
"resolveWith:" : "topa 11/15/2017 17:31",
15+
"description" : "merged 10/20/2008 09:23",
2216
"seasideAddonsUrl" : "pmm 9/12/2013 15:59",
23-
"seasideLGPLUrl" : "pmm 9/12/2013 15:59",
24-
"seasideUrl" : "pmm 9/12/2013 15:58",
17+
"resolveWith:" : "topa 11/15/2017 17:31",
18+
"addDependency:" : "merged 10/20/2008 09:33",
2519
"url" : "lr 2/10/2010 11:18",
26-
"url:" : "lr 2/17/2010 15:18" } }
20+
"printOn:" : "merged 10/20/2008 09:24",
21+
"addDependenciesTo:" : "lr 9/5/2009 18:35",
22+
"url:" : "lr 2/17/2010 15:18",
23+
"isMIT" : "lr 10/25/2009 15:19"
24+
},
25+
"class" : {
26+
"greaseCore" : "pmm 9/12/2013 16:00",
27+
"grPackages" : "JohanBrichau 12/15/2013 18:27"
28+
}
29+
}
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{
2-
"category" : "Grease-Core",
3-
"classinstvars" : [
4-
],
5-
"classvars" : [
6-
],
72
"commentStamp" : "pmm 9/14/2013 15:53",
3+
"super" : "GRObject",
4+
"category" : "Grease-Core",
5+
"classinstvars" : [ ],
6+
"pools" : [ ],
7+
"classvars" : [ ],
88
"instvars" : [
99
"name",
1010
"description",
1111
"dependencies",
1212
"license",
13-
"url" ],
13+
"url"
14+
],
1415
"name" : "GRPackage",
15-
"pools" : [
16-
],
17-
"super" : "GRObject",
18-
"type" : "normal" }
16+
"type" : "normal"
17+
}

0 commit comments

Comments
 (0)
X Tutup