Skip to content

Conversation

randruc
Copy link
Contributor

@randruc randruc commented Feb 13, 2025

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.

…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();
Copy link
Contributor

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 strings and using current culture dependent operations.

I know the switch is convenient, but not when dealing with strings.

}

foreach (string extension in extensions)
var extensions = extensionList.Split(',');
Copy link
Contributor

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 strings.

Consider using StringTokenizer

break;

default:
unknownExtensionsStringBuilder.Append(extension.Trim());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimming again?

@randruc
Copy link
Contributor Author

randruc commented Feb 14, 2025

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.

@sipsorcery
Copy link
Member

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.

@randruc
Copy link
Contributor Author

randruc commented Feb 14, 2025

Thanks for the review. That means that the visibility of the member could be restricted. I'll think about it.
I will update the submitted code with the suggestions made by @paulomorgado.
Now that I know that we don't want to keep the original mechanics of this function, I'll improve that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants