@@ -116,8 +116,7 @@ String str(double self) {
116
116
InternalFormat .Spec spec = new InternalFormat .Spec (' ' , '>' , InternalFormat .Spec .NONE , false , InternalFormat .Spec .UNSPECIFIED , false , 0 , 'r' );
117
117
FloatFormatter f = new FloatFormatter (getCore (), spec );
118
118
f .setMinFracDigits (1 );
119
- String result = f .format (self ).getResult ();
120
- return result ;
119
+ return f .format (self ).getResult ();
121
120
}
122
121
123
122
public static StrNode create () {
@@ -136,21 +135,20 @@ abstract static class FormatNode extends PythonBinaryBuiltinNode {
136
135
137
136
@ Specialization
138
137
String format (double self , String formatString ,
139
- @ Cached ("create()" ) StrNode strNode ) {
140
- if (shouldBeAsStr (formatString )) {
138
+ @ Cached ("create()" ) StrNode strNode ,
139
+ @ Cached ("createBinaryProfile()" ) ConditionProfile strProfile ,
140
+ @ Cached ("createBinaryProfile()" ) ConditionProfile unknownProfile ) {
141
+ if (strProfile .profile (shouldBeAsStr (formatString ))) {
141
142
return strNode .str (self );
142
143
}
143
144
InternalFormat .Spec spec = InternalFormat .fromText (getCore (), formatString , __FORMAT__ );
144
145
FloatFormatter formatter = prepareFormatter (spec );
145
- if (formatter != null ) {
146
- formatter .format (self );
147
- return formatter .pad ().getResult ();
148
-
149
- } else {
146
+ if (unknownProfile .profile (formatter == null )) {
150
147
// The type code was not recognised in prepareFormatter
151
148
throw Formatter .unknownFormat (getCore (), spec .type , "float" );
152
149
}
153
-
150
+ formatter .format (self );
151
+ return formatter .pad ().getResult ();
154
152
}
155
153
156
154
private FloatFormatter prepareFormatter (InternalFormat .Spec spec ) {
@@ -175,9 +173,7 @@ private FloatFormatter prepareFormatter(InternalFormat.Spec spec) {
175
173
// spec may be incomplete. The defaults are those commonly used for numeric
176
174
// formats.
177
175
InternalFormat .Spec usedSpec = spec .withDefaults (InternalFormat .Spec .NUMERIC );
178
- FloatFormatter formatter = new FloatFormatter (getCore (), usedSpec );
179
- return formatter ;
180
-
176
+ return new FloatFormatter (getCore (), usedSpec );
181
177
default :
182
178
return null ;
183
179
}
0 commit comments