Skip to content

Commit

Permalink
std/path: make globMatch work with @nogc
Browse files Browse the repository at this point in the history
  • Loading branch information
ljmf00-wekaio committed Sep 29, 2024
1 parent 59b3715 commit f0085e8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions std/path.d
Original file line number Diff line number Diff line change
Expand Up @@ -3396,7 +3396,10 @@ do
}
else
{
import core.memory : pureMalloc, pureFree;
C[] pattmp;
scope(exit) if (pattmp !is null) pureFree(pattmp.ptr);

for (size_t pi = 0; pi < pattern.length; pi++)
{
const pc = pattern[pi];
Expand Down Expand Up @@ -3482,9 +3485,10 @@ do
* pattern[pi0 .. pi-1] ~ pattern[piRemain..$]
*/
if (pattmp is null)
{
// Allocate this only once per function invocation.
// Should do it with malloc/free, but that would make it impure.
pattmp = new C[pattern.length];
pattmp = (cast(C*)pureMalloc(C.sizeof * pattern.length))[0 .. pattern.length];
}

const len1 = pi - 1 - pi0;
pattmp[0 .. len1] = pattern[pi0 .. pi - 1];
Expand Down Expand Up @@ -3518,7 +3522,7 @@ do
}

///
@safe unittest
@safe @nogc unittest
{
assert(globMatch("foo.bar", "*"));
assert(globMatch("foo.bar", "*.*"));
Expand Down

0 comments on commit f0085e8

Please sign in to comment.