On Tue, 25 May 2021 14:53:44 GMT, Patrick Concannon <pconcan...@openjdk.org> 
wrote:

>> src/java.base/share/classes/java/io/StreamTokenizer.java line 795:
>> 
>>> 793:                  * case statements
>>> 794:                  */
>>> 795:                 if (ttype < 256 && ((ctype[ttype] & CT_QUOTE) != 0)) {
>> 
>> Maybe (since its easier to grok the yield rather than the assignment of ret 
>> in branches):
>> 
>>     String ret = switch (ttype) {
>>             case TT_EOF     -> "EOF";
>>             case TT_EOL     -> "EOL";
>>             case TT_WORD    -> sval;
>>             case TT_NUMBER  -> "n=" + nval;
>>             case TT_NOTHING -> "NOTHING";
>>             default         -> {
>>                 /*
>>                  * ttype is the first character of either a quoted string or
>>                  * is an ordinary character. ttype can definitely not be less
>>                  * than 0, since those are reserved values used in the 
>> previous
>>                  * case statements
>>                  */
>>                 if (ttype < 256 && ((ctype[ttype] & CT_QUOTE) != 0)) {
>>                     yield sval;
>>                 }
>>                 char s[] = new char[3];
>>                 s[0] = s[2] = ''';
>>                 s[1] = (char) ttype;
>>                 yield new String(s);
>>             }
>>         };
>>         return "Token[" + ret + "], line " + LINENO;
>
> Code updated as suggested. See adc8af4

The snippet above both uses yield in the default case, and also removes the 
assignments from the other arms. adc8af4 overlooks the redundant assignments in 
the non-default cases.

-------------

PR: https://git.openjdk.java.net/jdk/pull/4182

Reply via email to