Forráskód Böngészése

[hxcpp] Do not assume utf8 on hxcpp. Add optimization for Std.string in the case of passed String

hughsando 7 éve
szülő
commit
bae1bd24e5
3 módosított fájl, 6 hozzáadás és 4 törlés
  1. 2 0
      std/cpp/_std/Std.hx
  2. 2 2
      std/haxe/crypto/Md5.hx
  3. 2 2
      std/haxe/crypto/Sha256.hx

+ 2 - 0
std/cpp/_std/Std.hx

@@ -19,6 +19,8 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
+
+@:headerClassCode("\t\tstatic inline String string(String &s) { return s; }")
 @:coreApi class Std {
 	@:keep public static function is( v : Dynamic, t : Dynamic ) : Bool {
 		return untyped __global__.__instanceof(v,t);

+ 2 - 2
std/haxe/crypto/Md5.hx

@@ -133,7 +133,7 @@ class Md5 {
 	}
 
 	static function str2blks( str : String ){
-#if !(neko || cpp)
+#if !(neko || (cpp && !hxcpp_smart_strings))
 		var str = haxe.io.Bytes.ofString(str);
 #end
 		var nblk = ((str.length + 8) >> 6) + 1;
@@ -153,7 +153,7 @@ class Md5 {
 		var max = str.length;
 		var l = max * 8;
 		while( i < max ) {
-			blks[i >> 2] |= #if !(neko || cpp) str.get(i) #else StringTools.fastCodeAt(str, i) #end << (((l + i) % 4) * 8);
+			blks[i >> 2] |= #if !(neko || (cpp && !hxcpp_smart_strings)) str.get(i) #else StringTools.fastCodeAt(str, i) #end << (((l + i) % 4) * 8);
 			i++;
 		}
 		blks[i >> 2] |= 0x80 << (((l + i) % 4) * 8);

+ 2 - 2
std/haxe/crypto/Sha256.hx

@@ -105,7 +105,7 @@ class Sha256 {
 		Append padding bits and the length, as described in the SHA1 standard.
 	 */
 	static function str2blks( s :String ) : Array<Int> {
-#if !(neko || cpp)
+#if !(neko || (cpp && !hxcpp_smart_strings))
 		var s = haxe.io.Bytes.ofString(s);
 #end
 		var nblk = ((s.length + 8) >> 6) + 1;
@@ -115,7 +115,7 @@ class Sha256 {
 			blks[i] = 0;
 		for (i in 0...s.length){
 			var p = i >> 2;
-			blks[p] |= #if !(neko || cpp) s.get(i) #else s.charCodeAt(i) #end << (24 - ((i & 3) << 3));
+			blks[p] |= #if !(neko || (cpp && !hxcpp_smart_strings)) s.get(i) #else s.charCodeAt(i) #end << (24 - ((i & 3) << 3));
 		}
 		var i = s.length;
 		var p = i >> 2;