Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Add InplaceStringFormatter #717

Closed
wants to merge 1 commit into from
Closed

Add InplaceStringFormatter #717

wants to merge 1 commit into from

Conversation

pakrym
Copy link
Contributor

@pakrym pakrym commented Sep 30, 2016

Intended to be used instead of pooled StringBuilder or string.Concat when all parts of string are known.
Does only 1 allocation of resulting string.

@benaadams @davidfowl @Tratcher @halter73 @rynowak

@pakrym
Copy link
Contributor Author

pakrym commented Sep 30, 2016

Use cases: #699, #716

@Tratcher
Copy link
Member

Something this fundamental belongs in Extensions/Common, or at least down in WebUtils

fixed (char* value = _value)
fixed (char* pDomainToken = s)
{
Unsafe.CopyBlock(value + _offset, pDomainToken, (uint)s.Length * 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

While this might currently work, don't think you can use CopyBlock as the spec says it expects all writes to be aligned dotnet/coreclr#7198 (comment)

ECMA-355 says:
"cpblk assumes that both destaddr and srcaddr are aligned to the natural size of the machine (but see the unaligned. prefix instruction). The operation of the cpblk instruction can be altered by an immediately preceding volatile. or unaligned. prefix instruction.

Might want to get a Unsafe.CopyBlockUnaligned added. This has also been pointed out in its use in corefxlabs

@benaadams
Copy link
Contributor

Raised issue for unaligned https://github.com/dotnet/corefx/issues/12243

@pakrym
Copy link
Contributor Author

pakrym commented Sep 30, 2016

Moved to dotnet/extensions#157

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

Successfully merging this pull request may close these issues.

4 participants