Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace string.StartsWith with a custom version
Saves about 3% on startup since we're not checking CultureInfo.
  • Loading branch information
sorear committed Nov 17, 2010
1 parent c861224 commit bdf7346
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Niecza.proj
Expand Up @@ -39,7 +39,8 @@
<Target Name="Kernel.dll" Inputs="lib\Kernel.cs;lib\Cursor.cs;lib/JSYNC.cs"
Outputs="obj\Kernel.dll">
<Csc Sources="lib\Kernel.cs;lib\Cursor.cs;lib\JSYNC.cs" TargetType="library"
OutputAssembly="obj\Kernel.dll" EmitDebugInformation="true"/>
OutputAssembly="obj\Kernel.dll" EmitDebugInformation="true"
AllowUnsafeBlocks="true"/>
</Target>

<Target Name="CORE.cs" Inputs="@(CompilerPerl);obj\SAFE.store;lib\CORE.setting" Outputs="obj\CORE.cs;obj\CORE.store" DependsOnTargets="SAFE.cs;Grammar;PerlTask">
Expand Down
17 changes: 16 additions & 1 deletion lib/Cursor.cs
Expand Up @@ -1439,6 +1439,21 @@ public class Lexer {
return ret;
}

// s1 must not have embedded nuls
private static unsafe bool StartsWithInvariant(string s1, string s2) {
fixed (char* st1 = s1) {
char* p1 = st1;
fixed (char* st2 = s2) {
char* p2 = st2;
while (*p1 != '\0' && *p1 == *p2) {
p1++;
p2++;
}
return (*p1 == '\0');
}
}
}

public static DynObject[] ResolveProtoregex(LexerCache lc,
string name) {
DynObject[] ret;
Expand Down Expand Up @@ -1467,7 +1482,7 @@ public class Lexer {
if (proto != k.Can(name))
continue;
foreach (KeyValuePair<string,IP6> o in k.ord_methods) {
if (!o.Key.StartsWith(filter))
if (!StartsWithInvariant(filter, o.Key))
continue;
if (cursor_class.Can(o.Key) == o.Value) {
raword.Add((DynObject) o.Value);
Expand Down

0 comments on commit bdf7346

Please sign in to comment.