Skip to content

Commit 11e8e8a

Browse files
committed
Fixed: Spawn decoder only when running loadFromMemory, added memmove and strchr implementation to internal stdc and use new redub version
1 parent 1eadf45 commit 11e8e8a

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

modules/assets/source/hip/assets/image.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class Image : HipAsset, IImage
4343
path = sanitizePath(path);
4444
super("Image_"~path);
4545
imagePath = path;
46-
decoder = getDecoder(path);
4746
}
4847
///Loads an arbitrary buffer which will be decoded by the decoder.
4948
this(in string path, in ubyte[] buffer, void delegate(IImage self) onSuccess, void delegate() onFailure)
@@ -87,6 +86,8 @@ public class Image : HipAsset, IImage
8786
{
8887
if(data.length == 0)
8988
throw new Exception("No data was passed to load Image. Could not load image at path "~imagePath);
89+
if(decoder is null)
90+
decoder = getDecoder(imagePath);
9091

9192
if(!(decoder.startDecoding(data, ()
9293
{

modules/d_std/source/core/stdc/string.d

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ extern(C) extern @nogc nothrow pure
1212

1313
version(CustomRuntime)
1414
{
15-
public import object: memcpy, memset, memcmp;
15+
public import object: memcpy, memset, memcmp, memmove;
1616
}
1717
else
1818
{
1919
void* memcpy(void* dest, const(void*) src, size_t n);
2020
void* memset(void* str, int c, size_t n);
2121
int memcmp(const(void*) str1, const(void*) str2, size_t n) pure;
22+
void* memmove(return scope void* s1, scope const void* s2, size_t n) pure;
23+
const(char)* strchr(const(char)* str, char c) pure @nogc nothrow @trustred;
2224
}
2325

2426
version(CustomDefinitions)
@@ -43,7 +45,42 @@ extern(C) extern @nogc nothrow pure
4345
while(str[len++] != '\0'){}
4446

4547
return len;
48+
}
49+
50+
const(char)* strchr(const(char)* str, char c) pure @nogc nothrow @trusted
51+
{
52+
enum ulong mask = 0x8080808080808080;
53+
enum ulong magic = 0x0101010101010101;
54+
ulong cc = cast(ubyte)c;
55+
cc |= cc << 8;
56+
cc |= cc << 16;
57+
cc |= cc << 32;
58+
59+
auto ptr = cast(const(ulong)*)str;
60+
size_t offset = 0;
4661

62+
for(;; ptr++, offset += 8)
63+
{
64+
ulong value = *ptr;
65+
66+
// detect match with c
67+
ulong diff = value ^ cc;
68+
if(((diff - magic) & ~diff & mask) != 0)
69+
break;
70+
71+
// detect null terminator
72+
if(((value - magic) & ~value & mask) != 0)
73+
break;
74+
}
75+
76+
// refine, byte by byte
77+
for(;; offset++)
78+
{
79+
if(str[offset] == c)
80+
return str + offset;
81+
if(str[offset] == '\0')
82+
return null;
83+
}
4784
}
4885

4986

tools/hbuild/dub.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"copyright": "Copyright © 2023, Hipreme",
66
"dependencies": {
77
"arsd-official:terminal": "~>11.5.0",
8-
"redub": "~>1.24.11",
8+
"redub": "~>1.24.13",
99
"handy-httpd": "~>8.4.3",
1010
"archive": "~>0.7.1",
1111
"my-ip": "~>0.2.0",

0 commit comments

Comments
 (0)