Last active
June 14, 2019 20:45
-
-
Save EliCDavis/c83dbd8cec7ed3aba5e45a631fa4328a to your computer and use it in GitHub Desktop.
Unity's faster implementations for string operations found: https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity5.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool CustomEndsWith(string a, string b) { | |
int ap = a.Length - 1; | |
int bp = b.Length - 1; | |
while (ap >= 0 && bp >= 0 && a [ap] == b [bp]) { | |
ap--; | |
bp--; | |
} | |
return (bp < 0 && a.Length >= b.Length) || (ap < 0 && b.Length >= a.Length); | |
} | |
public static bool CustomStartsWith(string a, string b) { | |
int aLen = a.Length; | |
int bLen = b.Length; | |
int ap = 0; int bp = 0; | |
while (ap < aLen && bp < bLen && a [ap] == b [bp]) { | |
ap++; | |
bp++; | |
} | |
return (bp == bLen && aLen >= bLen) || (ap == aLen && bLen >= aLen); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment