@@ -33,7 +33,7 @@ private static bool NeedsTruncation(string[] array)
3333 // Optimization: only count the actual number of bytes if there is the possibility
3434 // of the strings exceeding maxStringBytes
3535 return encoding . GetMaxByteCount ( array . Sum ( s => s . Length ) ) > maxStringBytes &&
36- array . Sum ( s => encoding . GetByteCount ( s ) ) > maxStringBytes ;
36+ array . Sum ( encoding . GetByteCount ) > maxStringBytes ;
3737 }
3838
3939 private static void WriteString ( ITrapBuilder tb , string s ) => tb . Append ( EncodeString ( s ) ) ;
@@ -91,66 +91,60 @@ public void EmitToTrapBuilder(ITrapBuilder tb)
9191 foreach ( var a in Args )
9292 {
9393 if ( column > 0 ) tb . Append ( ", " ) ;
94- if ( a is Label l )
94+ switch ( a )
9595 {
96- l . AppendTo ( tb ) ;
97- }
98- else if ( a is IEntity e )
99- {
100- e . Label . AppendTo ( tb ) ;
101- }
102- else if ( a is string s )
103- {
104- tb . Append ( "\" " ) ;
105- if ( NeedsTruncation ( s ) )
106- {
107- // Slow path
108- int remaining = maxStringBytes ;
109- WriteTruncatedString ( tb , s , ref remaining ) ;
110- }
111- else
112- {
113- // Fast path
114- WriteString ( tb , s ) ;
115- }
116- tb . Append ( "\" " ) ;
117- }
118- else if ( a is System . Enum )
119- {
120- tb . Append ( ( int ) a ) ;
121- }
122- else if ( a is int i )
123- {
124- tb . Append ( i ) ;
125- }
126- else if ( a is string [ ] array )
127- {
128- tb . Append ( "\" " ) ;
129- if ( NeedsTruncation ( array ) )
130- {
131- // Slow path
132- int remaining = maxStringBytes ;
133- foreach ( var element in array )
134- WriteTruncatedString ( tb , element , ref remaining ) ;
135- }
136- else
137- {
138- // Fast path
139- foreach ( var element in array )
140- WriteString ( tb , element ) ;
141- }
142- tb . Append ( "\" " ) ;
143- }
144- else if ( a is null )
145- {
146- throw new InternalError ( "Attempt to write a null argument tuple {0} at column {1}" ,
147- Name , column ) ;
148- }
149- else
150- {
151- throw new InternalError ( "Attempt to write an invalid argument type {0} in tuple {1} at column {2}" ,
152- a . GetType ( ) , Name , column ) ;
96+ case Label l :
97+ l . AppendTo ( tb ) ;
98+ break ;
99+ case IEntity e :
100+ e . Label . AppendTo ( tb ) ;
101+ break ;
102+ case string s :
103+ tb . Append ( "\" " ) ;
104+ if ( NeedsTruncation ( s ) )
105+ {
106+ // Slow path
107+ int remaining = maxStringBytes ;
108+ WriteTruncatedString ( tb , s , ref remaining ) ;
109+ }
110+ else
111+ {
112+ // Fast path
113+ WriteString ( tb , s ) ;
114+ }
115+ tb . Append ( "\" " ) ;
116+ break ;
117+ case System . Enum en :
118+ tb . Append ( ( int ) a ) ;
119+ break ;
120+ case int i :
121+ tb . Append ( i ) ;
122+ break ;
123+ case string [ ] array :
124+ tb . Append ( "\" " ) ;
125+ if ( NeedsTruncation ( array ) )
126+ {
127+ // Slow path
128+ int remaining = maxStringBytes ;
129+ foreach ( var element in array )
130+ WriteTruncatedString ( tb , element , ref remaining ) ;
131+ }
132+ else
133+ {
134+ // Fast path
135+ foreach ( var element in array )
136+ WriteString ( tb , element ) ;
137+ }
138+ tb . Append ( "\" " ) ;
139+ break ;
140+ case null :
141+ throw new InternalError ( "Attempt to write a null argument tuple {0} at column {1}" ,
142+ Name , column ) ;
143+ default :
144+ throw new InternalError ( "Attempt to write an invalid argument type {0} in tuple {1} at column {2}" ,
145+ a . GetType ( ) , Name , column ) ;
153146 }
147+
154148 ++ column ;
155149 }
156150 tb . Append ( ")" ) ;
0 commit comments