[Mono-dev] Patch for String.Trim

Andreas Nahr ClassDevelopment at A-SoftTech.com
Fri Jan 18 14:27:56 EST 2008


Hi,

The attached patch implements String.Trim and the related methods in pure
managed code. It also contains a few optimizations that will speed up the
calls by a considerable amount. A big goal was to optimize common cases
(like the Trim call without parameters).
>From some testing:
"               H ".Trim(): 7441 -> 2754 (+170%)
"Test".Trim(null) : 1332 -> 421 (+216%)
"HAAAAAAAAAAAAAAHAH".Trim( new Char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', '
' }): 631 -> 550 (+14%)
"HAAAAAAAAAAAAAAHAH".TrimEnd(): 1820 -> 1290 (+41%)
tests with custom trims AND lots of characters that get trimed like:
"               H ".Trim( new Char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', '
' }): 6350 -> 9303 (-46%)
got slower. The reason for that is obviously that the c-code gets better
optimization than the c# code and the overhead of the managed impl. is a
little bit higher.


Please review and commit the patch.

Other small changes:
* Added MonoTodos to some methods that are currently incorrectly implemented
* Added a CharCopy
* Slightly optimized the Concat Methods

The patch does not remove the unused code from mono itself as I'm not really
comfortable hacking inside the runtime, feel free to remove the now-unused
ves_icall_System_String_InternalTrim in string-icalls.

Greetings
Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: String.patch
Type: application/octet-stream
Size: 9169 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080118/a550af67/attachment.obj 


More information about the Mono-devel-list mailing list