Minimize System.Version formatting buffer's length#102508
Conversation
Change the length of the char buffer used in Version.ToString() from 47 to 43 chars (4 non-negative Int32s + 3 periods). Even if a version has invalid internal state (any component less than -1), the TryFormat method just casts them to UInt32 anyway.
|
Oh, I didn't realize that |
|
To be fair, this doesn't reduce the actual stack allocation size - JIT is going to round up both to % 16 anyway, e.g. see sharplab |
Number.Int32NumberBufferLength is only used in System.Number class and here. The extra 1 to length is designated for the terminating nulls. It would make more sense not to use it here.
|
I see. 😄 Then, I guess it could still improve readability of the decompiled code. It was confusing to see 47 characters allocated when the actual maximum length is 43. On another note, looks like runtime/src/libraries/Common/src/System/Number.NumberBuffer.cs Lines 13 to 16 in 153a94b |
|
Thank you, but I'd rather keep it how it is today. I think it's more maintainable as it is currently and this doesn't actually improve perf. |
Change the length of the char buffer used in
Version.ToString()from 47 to 43 chars (4 non-negativeInt32s + 3 periods).2147483647.2147483647.2147483647.2147483647. Even if a version has invalid internal state (any component less than -1), theTryFormatmethod just casts them toUInt32anyway.