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

Add InplaceStringFormatter - #717

Closed
pakrym wants to merge 1 commit into
devfrom
pakrym/isp
Closed

pakrym wants to merge 1 commit into
devfrom
pakrym/isp

Conversation

@pakrym

@pakrym pakrym commented Sep 30, 2016

Copy link
Copy Markdown
Contributor

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

pakrym commented Sep 30, 2016

Copy link
Copy Markdown
Contributor Author

Use cases: #699, #716

@Tratcher

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@pakrym

pakrym commented Sep 30, 2016

Copy link
Copy Markdown
Contributor Author

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