@@ -312,20 +312,24 @@ func (t *Type) Format(s fmt.State, v rune) {
312
312
name = pkg + "." + name
313
313
}
314
314
315
+ writeString := func (str string ) {
316
+ _ , _ = s .Write ([]byte (str ))
317
+ }
318
+
315
319
if t .Opaque () {
316
320
if name == "" {
317
321
name = fmt .Sprintf ("<anon %s>" , t .Kind ())
318
322
}
319
323
if t .typ .Kind == coroutinev1 .Kind_KIND_POINTER {
320
324
name = "*" + name
321
325
}
322
- s . Write ([] byte ( name ) )
326
+ writeString ( name )
323
327
return
324
328
}
325
329
326
330
verbose := s .Flag ('+' ) || s .Flag ('#' )
327
331
if name != "" && ! verbose {
328
- s . Write ([] byte ( name ) )
332
+ writeString ( name )
329
333
return
330
334
}
331
335
@@ -386,7 +390,7 @@ func (t *Type) Format(s fmt.State, v rune) {
386
390
default :
387
391
result = primitiveKind
388
392
}
389
- s . Write ([] byte ( result ) )
393
+ writeString ( result )
390
394
return
391
395
}
392
396
@@ -412,82 +416,82 @@ func (t *Type) Format(s fmt.State, v rune) {
412
416
if name != "" {
413
417
elemPrefix = fmt .Sprintf ("(%s=%s" , name , elemPrefix )
414
418
}
415
- s . Write ([] byte ( elemPrefix ) )
419
+ writeString ( elemPrefix )
416
420
t .Elem ().Format (withoutFlags {s }, v )
417
421
if name != "" {
418
- s . Write ([] byte ( ")" ) )
422
+ writeString ( ")" )
419
423
}
420
424
return
421
425
}
422
426
423
427
if name != "" {
424
- s . Write ([] byte ( fmt .Sprintf ("(%s=" , name ) ))
428
+ writeString ( fmt .Sprintf ("(%s=" , name ))
425
429
}
426
430
switch t .typ .Kind {
427
431
case coroutinev1 .Kind_KIND_FUNC :
428
- s . Write ([] byte ( "func(" ) )
432
+ writeString ( "func(" )
429
433
paramCount := t .NumParam ()
430
434
for i := 0 ; i < paramCount ; i ++ {
431
435
if i > 0 {
432
- s . Write ([] byte ( ", " ) )
436
+ writeString ( ", " )
433
437
}
434
438
if i == paramCount - 1 && t .Variadic () {
435
- s . Write ([] byte ( "..." ) )
439
+ writeString ( "..." )
436
440
}
437
441
t .Param (i ).Format (withoutFlags {s }, v )
438
442
}
439
- s . Write ([] byte ( ")" ) )
443
+ writeString ( ")" )
440
444
n := t .NumResult ()
441
445
if n > 0 {
442
- s . Write ([] byte ( " " ) )
446
+ writeString ( " " )
443
447
}
444
448
if n > 1 {
445
- s . Write ([] byte ( "(" ) )
449
+ writeString ( "(" )
446
450
}
447
451
for i := 0 ; i < n ; i ++ {
448
452
if i > 0 {
449
- s . Write ([] byte ( ", " ) )
453
+ writeString ( ", " )
450
454
}
451
455
t .Result (i ).Format (withoutFlags {s }, v )
452
456
}
453
457
if n > 1 {
454
- s . Write ([] byte ( ")" ) )
458
+ writeString ( ")" )
455
459
}
456
460
if name != "" {
457
- s . Write ([] byte ( ")" ) )
461
+ writeString ( ")" )
458
462
}
459
463
460
464
case coroutinev1 .Kind_KIND_MAP :
461
- s . Write ([] byte ( "map[" ) )
465
+ writeString ( "map[" )
462
466
t .Key ().Format (withoutFlags {s }, v )
463
- s . Write ([] byte ( "]" ) )
467
+ writeString ( "]" )
464
468
t .Elem ().Format (withoutFlags {s }, v )
465
469
466
470
case coroutinev1 .Kind_KIND_STRUCT :
467
471
n := t .NumField ()
468
472
if n == 0 {
469
- s . Write ([] byte ( "struct{}" ) )
473
+ writeString ( "struct{}" )
470
474
} else {
471
- s . Write ([] byte ( "struct{ " ) )
475
+ writeString ( "struct{ " )
472
476
for i := 0 ; i < n ; i ++ {
473
477
if i > 0 {
474
- s . Write ([] byte ( "; " ) )
478
+ writeString ( "; " )
475
479
}
476
480
f := t .Field (i )
477
481
if ! f .Anonymous () {
478
- s . Write ([] byte ( f .Name () ))
479
- s . Write ([] byte ( " " ) )
482
+ writeString ( f .Name ())
483
+ writeString ( " " )
480
484
}
481
485
f .Type ().Format (withoutFlags {State : s }, v )
482
486
}
483
- s . Write ([] byte ( " }" ) )
487
+ writeString ( " }" )
484
488
}
485
489
486
490
default :
487
- s . Write ([] byte ( "invalid" ) )
491
+ writeString ( "invalid" )
488
492
}
489
493
if name != "" {
490
- s . Write ([] byte ( ")" ) )
494
+ writeString ( ")" )
491
495
}
492
496
}
493
497
0 commit comments