@@ -116,8 +116,7 @@ String str(double self) {
116116 InternalFormat .Spec spec = new InternalFormat .Spec (' ' , '>' , InternalFormat .Spec .NONE , false , InternalFormat .Spec .UNSPECIFIED , false , 0 , 'r' );
117117 FloatFormatter f = new FloatFormatter (getCore (), spec );
118118 f .setMinFracDigits (1 );
119- String result = f .format (self ).getResult ();
120- return result ;
119+ return f .format (self ).getResult ();
121120 }
122121
123122 public static StrNode create () {
@@ -136,21 +135,20 @@ abstract static class FormatNode extends PythonBinaryBuiltinNode {
136135
137136 @ Specialization
138137 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 ))) {
141142 return strNode .str (self );
142143 }
143144 InternalFormat .Spec spec = InternalFormat .fromText (getCore (), formatString , __FORMAT__ );
144145 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 )) {
150147 // The type code was not recognised in prepareFormatter
151148 throw Formatter .unknownFormat (getCore (), spec .type , "float" );
152149 }
153-
150+ formatter .format (self );
151+ return formatter .pad ().getResult ();
154152 }
155153
156154 private FloatFormatter prepareFormatter (InternalFormat .Spec spec ) {
@@ -175,9 +173,7 @@ private FloatFormatter prepareFormatter(InternalFormat.Spec spec) {
175173 // spec may be incomplete. The defaults are those commonly used for numeric
176174 // formats.
177175 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 );
181177 default :
182178 return null ;
183179 }
0 commit comments