-
Notifications
You must be signed in to change notification settings - Fork 485
Change the definition of enum SIPExtensions to allow using as a bitfield #1323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Change the definition of enum SIPExtensions to allow using as a bitfield #1323
Conversation
…eld. In class SIPHeader, members RequiredExtensions and SupportedExtensions can now become bitfields instead of lists of enums. This results in a smaller memory footprint. Modify static method ParseSIPExtensions accordingly, and eliminate all string concatenations by using a StringBuilder.
if (!String.IsNullOrEmpty(extension)) | ||
{ | ||
if (String.IsNullOrEmpty(extension) == false) | ||
var trimmedExtension = extension.Trim().ToLower(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is potentially creating 2 string
s and using current culture dependent operations.
I know the switch
is convenient, but not when dealing with string
s.
} | ||
|
||
foreach (string extension in extensions) | ||
var extensions = extensionList.Split(','); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allocates a string[]
and several string
s.
Consider using StringTokenizer
break; | ||
|
||
default: | ||
unknownExtensionsStringBuilder.Append(extension.Trim()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trimming again?
You are totally right. I kept the same existing logic of the function, but I agree that the string manipulations are not done the best way, and I can go further if needed. |
The flag enum is a good improvement. Happy to merge. The change is highly unlikely to affect any library users. If there are further string optimisations planned it would be better to get them in now. |
Thanks for the review. That means that the visibility of the member could be restricted. I'll think about it. |
Change the definition of enum SIPExtensions to allow using as a bitfieldeld.
In class SIPHeader, members RequiredExtensions and SupportedExtensions can now become bitfields instead of lists of enums.
This results in a smaller memory footprint.
Modify static method ParseSIPExtensions accordingly, and eliminate all string concatenations by using a StringBuilder.
Important
Although this approch is more idiomatic to C#, and reduces the memory footprint of the library, it is important to note that this modifies the public API, as members SupportedExtensions are RequiredExtensions are public. Please let me know what you think about it.