Update the ToString format of the BaseUnits/Dimensions - #1486
Conversation
- BaseUnits: no longer using the AbbeviationsCache - BaseDimensions: the exponent moved inside the dimension-brackets - BaseDimensions: minor performance improvements
lipchev
commented
Jan 1, 2025
@angularsen Happy new year, here's an easy one which we've talked about in #1452 I wasn't 100% sure back then (and I never actually meant for it to be optimal), but I did a quick benchmark and the publicstringToStringWithAppend(){if(Equals(Undefined)){return"Undefined";}varsb=newStringBuilder();if(Lengthis not null){sb.Append("[Length]: ").Append(Length).Append(", ");}if(Massis not null){sb.Append("[Mass]: ").Append(Mass).Append(", ");}if(Timeis not null){sb.Append("[Time]: ").Append(Time).Append(", ");}if(Currentis not null){sb.Append("[Current]: ").Append(Current).Append(", ");}if(Temperatureis not null){sb.Append("[Temperature]: ").Append(Temperature).Append(", ");}if(Amountis not null){sb.Append("[Amount]: ").Append(Amount).Append(", ");}if(LuminousIntensityis not null){sb.Append("[LuminousIntensity]: ").Append(LuminousIntensity).Append(", ");}if(sb.Length>2){sb.Length-=2;// Remove the trailing ", "}returnsb.ToString();} |
Uh oh!
There was an error while loading. Please reload this page.
angularsen
left a comment
There was a problem hiding this comment.
Looks good to me, a couple of suggestions
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
angularsen
commented
Jan 2, 2025
I meant to answer and forgot, happy new year @lipchev 🎉 I'm very glad you are around to learn from, and discuss and share ideas with, I really appreciate it ❤️ |
BaseUnits: no longer using theAbbeviationsCache, the new format isL=Meter, M=Kilogram, T=SecondBaseDimensions: the exponent moved inside the dimension-brackets:[Length][Time^-1]BaseDimensions: minor performance improvementsAs mentioned in #1452, the main motivation here is the removal of the potential side effects of accessing/loading the unit abbreviations (e.g. during the
QuantityInfoconstruction)