Skip to content

Commit 01833b9

Browse files
committed
Optimize key_from_id
1 parent e30da03 commit 01833b9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/mono/mono/metadata/bundled-resources.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,30 @@ bundled_resources_is_known_assembly_extension (const char *ext)
7373
#endif
7474
}
7575

76+
// strrchr calls strlen, so we need to do a search with known length instead
77+
// for some reason memrchr is defined in a header but the build fails when we try to use it
78+
static const char *
79+
g_memrchr (const char *s, char c, size_t n)
80+
{
81+
while (n--)
82+
if (s[n] == c)
83+
return (void *)(s + n);
84+
return NULL;
85+
}
86+
7687
// If a bundled resource has a known assembly extension, we strip the extension from its name
7788
// This ensures that lookups for foo.dll will work even if the assembly is in a webcil container
7889
static char *
7990
key_from_id (const char *id, char *buffer, guint buffer_len)
8091
{
8192
size_t id_length = strlen (id),
8293
extension_offset = -1;
83-
const char *extension = strrchr (id, '.');
94+
const char *extension = g_memrchr (id, '.', id_length);
8495
if (extension)
8596
extension_offset = extension - id;
8697
if (!buffer) {
8798
buffer_len = (guint)(id_length + 1);
88-
buffer = g_malloc(buffer_len);
99+
buffer = g_malloc (buffer_len);
89100
}
90101
buffer[0] = 0;
91102

0 commit comments

Comments
 (0)