The Trunk: Collections-nice.868.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-nice.868.mcz

commits-2
Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.868.mcz

==================== Summary ====================

Name: Collections-nice.868
Author: nice
Time: 28 December 2019, 1:23:35.502843 pm
UUID: e4026d16-31b5-430f-8c22-6475db37bb91
Ancestors: Collections-mt.866

Fix RunArrayTest>>testAt2 (testing access out of bounds)

Beware, Text depends on this feature of accessing runs out of bounds, because the characterIndex might be past end.

To avoid problems, transform previous #at: implementation into #atPin: and use that in Text.
#atPin: clamps the index in accessible range.

=============== Diff against Collections-mt.866 ===============

Item was changed:
  ----- Method: RunArray>>at: (in category 'accessing') -----
  at: index
 
+ self at: index setRunOffsetAndValue: [:run :offset :value |
+ offset < 0 ifTrue: [ self errorSubscriptBounds: index ].
+ offset >= (runs at: run) ifTrue: [ self errorSubscriptBounds: index ].
+ ^value]!
- self at: index setRunOffsetAndValue: [:run :offset :value | ^value]!

Item was added:
+ ----- Method: RunArray>>atPin: (in category 'accessing') -----
+ atPin: index
+
+ self at: index setRunOffsetAndValue: [:run :offset :value | ^value]!

Item was changed:
  ----- Method: Text>>alignmentAt:ifAbsent: (in category 'emphasis') -----
  alignmentAt: characterIndex ifAbsent: aBlock
  | attributes emph |
  self size = 0 ifTrue: [^aBlock value].
  emph := nil.
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
  attributes do:[:att | (att isKindOf: TextAlignment) ifTrue:[emph := att]].
  emph ifNil: [ ^aBlock value ].
  ^emph alignment!

Item was changed:
  ----- Method: Text>>attributesAt: (in category 'emphasis') -----
  attributesAt: characterIndex
  "Answer the code for characters in the run beginning at characterIndex."
  "NB: no senders any more (supplanted by #attributesAt:forStyle: but retained for the moment in order not to break user code that may exist somewhere that still calls this"
  | attributes |
  self size = 0
  ifTrue: [^ Array with: (TextFontChange new fontNumber: 1)].  "null text tolerates access"
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
  ^ attributes!

Item was changed:
  ----- Method: Text>>attributesAt:do: (in category 'emphasis') -----
  attributesAt: characterIndex do: aBlock
  "Answer the code for characters in the run beginning at characterIndex."
  "NB: no senders any more (supplanted by #attributesAt:forStyle: but retained for the moment in order not to break user code that may exist somewhere that still calls this"
  self size = 0 ifTrue:[^self].
+ (runs atPin: characterIndex) do: aBlock!
- (runs at: characterIndex) do: aBlock!

Item was changed:
  ----- Method: Text>>attributesAt:forStyle: (in category 'emphasis') -----
  attributesAt: characterIndex forStyle: aTextStyle
  "Answer the code for characters in the run beginning at characterIndex."
  | attributes |
  self size = 0
  ifTrue: [^ Array with: (TextFontChange new fontNumber: aTextStyle defaultFontIndex)].  "null text tolerates access"
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
  ^ attributes!

Item was changed:
  ----- Method: Text>>colorAt:ifNone: (in category 'emphasis') -----
  colorAt: characterIndex ifNone: block
 
  self size = 0 ifTrue: [^ block value]. "null text tolerates access."
 
+ ^ (runs atPin: characterIndex)
- ^ (runs at: characterIndex)
  detect: [:attr | attr class == TextColor]
  ifFound: [:attr | attr color]
  ifNone: block!

Item was changed:
  ----- Method: Text>>emphasisAt: (in category 'emphasis') -----
  emphasisAt: characterIndex
  "Answer the fontfor characters in the run beginning at characterIndex."
  | attributes |
  self size = 0 ifTrue: [^ 0]. "null text tolerates access"
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
  ^attributes inject: 0 into:
  [:emph :att | emph bitOr: att emphasisCode].
  !

Item was changed:
  ----- Method: Text>>fontAt:withStyle: (in category 'emphasis') -----
  fontAt: characterIndex withStyle: aTextStyle
  "Answer the fontfor characters in the run beginning at characterIndex."
  | attributes font |
  self size = 0 ifTrue: [^ aTextStyle defaultFont]. "null text tolerates access"
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
  font := aTextStyle defaultFont.  "default"
  attributes do:
  [:att | att forFontInStyle: aTextStyle do: [:f | font := f]].
  ^ font!

Item was changed:
  ----- Method: Text>>fontNumberAt: (in category 'emphasis') -----
  fontNumberAt: characterIndex
  "Answer the fontNumber for characters in the run beginning at characterIndex."
  | attributes fontNumber |
  self size = 0 ifTrue: [^1]. "null text tolerates access"
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
  fontNumber := 1.
  attributes do: [:att | (att isMemberOf: TextFontChange) ifTrue: [fontNumber := att fontNumber]].
  ^ fontNumber
  !


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Collections-nice.868.mcz

marcel.taeumel
Hi Nicolas.

Beware, Text depends on this feature of accessing runs out of bounds, because the characterIndex might be past end.

Good catch!

Best,
Marcel

Am 29.12.2019 17:32:26 schrieb [hidden email] <[hidden email]>:

Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.868.mcz

==================== Summary ====================

Name: Collections-nice.868
Author: nice
Time: 28 December 2019, 1:23:35.502843 pm
UUID: e4026d16-31b5-430f-8c22-6475db37bb91
Ancestors: Collections-mt.866

Fix RunArrayTest>>testAt2 (testing access out of bounds)

Beware, Text depends on this feature of accessing runs out of bounds, because the characterIndex might be past end.

To avoid problems, transform previous #at: implementation into #atPin: and use that in Text.
#atPin: clamps the index in accessible range.

=============== Diff against Collections-mt.866 ===============

Item was changed:
----- Method: RunArray>>at: (in category 'accessing') -----
at: index

+ self at: index setRunOffsetAndValue: [:run :offset :value |
+ offset < 0="" iftrue:="" [="" self="" errorsubscriptbounds:="" index="">
+ offset >= (runs at: run) ifTrue: [ self errorSubscriptBounds: index ].
+ ^value]!
- self at: index setRunOffsetAndValue: [:run :offset :value | ^value]!

Item was added:
+ ----- Method: RunArray>>atPin: (in category 'accessing') -----
+ atPin: index
+
+ self at: index setRunOffsetAndValue: [:run :offset :value | ^value]!

Item was changed:
----- Method: Text>>alignmentAt:ifAbsent: (in category 'emphasis') -----
alignmentAt: characterIndex ifAbsent: aBlock
| attributes emph |
self size = 0 ifTrue: [^aBlock value].
emph := nil.
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
attributes do:[:att | (att isKindOf: TextAlignment) ifTrue:[emph := att]].
emph ifNil: [ ^aBlock value ].
^emph alignment!

Item was changed:
----- Method: Text>>attributesAt: (in category 'emphasis') -----
attributesAt: characterIndex
"Answer the code for characters in the run beginning at characterIndex."
"NB: no senders any more (supplanted by #attributesAt:forStyle: but retained for the moment in order not to break user code that may exist somewhere that still calls this"
| attributes |
self size = 0
ifTrue: [^ Array with: (TextFontChange new fontNumber: 1)]. "null text tolerates access"
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
^ attributes!

Item was changed:
----- Method: Text>>attributesAt:do: (in category 'emphasis') -----
attributesAt: characterIndex do: aBlock
"Answer the code for characters in the run beginning at characterIndex."
"NB: no senders any more (supplanted by #attributesAt:forStyle: but retained for the moment in order not to break user code that may exist somewhere that still calls this"
self size = 0 ifTrue:[^self].
+ (runs atPin: characterIndex) do: aBlock!
- (runs at: characterIndex) do: aBlock!

Item was changed:
----- Method: Text>>attributesAt:forStyle: (in category 'emphasis') -----
attributesAt: characterIndex forStyle: aTextStyle
"Answer the code for characters in the run beginning at characterIndex."
| attributes |
self size = 0
ifTrue: [^ Array with: (TextFontChange new fontNumber: aTextStyle defaultFontIndex)]. "null text tolerates access"
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
^ attributes!

Item was changed:
----- Method: Text>>colorAt:ifNone: (in category 'emphasis') -----
colorAt: characterIndex ifNone: block

self size = 0 ifTrue: [^ block value]. "null text tolerates access."

+ ^ (runs atPin: characterIndex)
- ^ (runs at: characterIndex)
detect: [:attr | attr class == TextColor]
ifFound: [:attr | attr color]
ifNone: block!

Item was changed:
----- Method: Text>>emphasisAt: (in category 'emphasis') -----
emphasisAt: characterIndex
"Answer the fontfor characters in the run beginning at characterIndex."
| attributes |
self size = 0 ifTrue: [^ 0]. "null text tolerates access"
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
^attributes inject: 0 into:
[:emph :att | emph bitOr: att emphasisCode].
!

Item was changed:
----- Method: Text>>fontAt:withStyle: (in category 'emphasis') -----
fontAt: characterIndex withStyle: aTextStyle
"Answer the fontfor characters in the run beginning at characterIndex."
| attributes font |
self size = 0 ifTrue: [^ aTextStyle defaultFont]. "null text tolerates access"
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
font := aTextStyle defaultFont. "default"
attributes do:
[:att | att forFontInStyle: aTextStyle do: [:f | font := f]].
^ font!

Item was changed:
----- Method: Text>>fontNumberAt: (in category 'emphasis') -----
fontNumberAt: characterIndex
"Answer the fontNumber for characters in the run beginning at characterIndex."
| attributes fontNumber |
self size = 0 ifTrue: [^1]. "null text tolerates access"
+ attributes := runs atPin: characterIndex.
- attributes := runs at: characterIndex.
fontNumber := 1.
attributes do: [:att | (att isMemberOf: TextFontChange) ifTrue: [fontNumber := att fontNumber]].
^ fontNumber
!