Перенос инициализации в класс 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 *.o
*.obj *.obj
*.lst *.lst
*.a

View file

@ -14,20 +14,13 @@ Add to `dub.json`:
```json ```json
{ {
"dependencies": { "libs": [
"sdiff": "~>0.1.0" "xdiff"
} ],
}
```
Or
```json
{
"dependencies": { "dependencies": {
"sdiff": { "sdiff": {
"repository": "git+https://git.zhirov.kz/dlang/sdiff.git", "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 ~ ")"); enforce(rc == 0, "xdl_set_allocator failed (rc=" ~ rc.to!string ~ ")");
} }
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 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;
}
protected: protected:
mmfile_t _inner; mmfile_t _inner;
public: public:
this(long bsize = 0) {
_inner = initMmfile(bsize);
}
final @property size_t size() final @property size_t size()
{ {
return xdl_mmfile_size(&_inner).to!size_t; return xdl_mmfile_size(&_inner).to!size_t;

View file

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

View file

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