Перенос инициализации в класс MM

This commit is contained in:
Alexander Zhirov 2025-09-16 14:20:21 +03:00
parent 8c388b1123
commit e0049496d3
Signed by: alexander
GPG key ID: C8D8BE544A27C511
5 changed files with 17 additions and 22 deletions

1
.gitignore vendored
View file

@ -14,3 +14,4 @@ sdiff-test-*
*.o
*.obj
*.lst
*.a

View file

@ -14,20 +14,13 @@ Add to `dub.json`:
```json
{
"dependencies": {
"sdiff": "~>0.1.0"
}
}
```
Or
```json
{
"libs": [
"xdiff"
],
"dependencies": {
"sdiff": {
"repository": "git+https://git.zhirov.kz/dlang/sdiff.git",
"version": "<hash from git>"
"version": "~0.1.0"
}
}
}

View file

@ -31,19 +31,22 @@ shared static this()
enforce(rc == 0, "xdl_set_allocator failed (rc=" ~ rc.to!string ~ ")");
}
mmfile_t initMmfile(size_t blockSize)
abstract class MM
{
private:
mmfile_t initMmfile(size_t blockSize)
{
mmfile_t mf;
auto rc = xdl_init_mmfile(&mf, blockSize.to!long, XDL_MMF_ATOMIC);
enforce(rc == 0, "xdl_init_mmfile failed (rc=" ~ rc.to!string ~ ")");
return mf;
}
abstract class MM
{
}
protected:
mmfile_t _inner;
public:
this(long bsize = 0) {
_inner = initMmfile(bsize);
}
final @property size_t size()
{
return xdl_mmfile_size(&_inner).to!size_t;

View file

@ -14,7 +14,7 @@ final class MMBlocks : MM
public:
this()
{
_inner = initMmfile(DEFAULT_BSIZE);
super(DEFAULT_BSIZE);
}
~this()

View file

@ -14,8 +14,6 @@ final class MMFile : MM
private:
void _write(const(ubyte)[] data)
{
_inner = initMmfile(0);
if (data.length > 0)
{
auto length = data.length.to!long;