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

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

1
.gitignore vendored
View file

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

View file

@ -12,22 +12,12 @@ A minimal D wrapper over [xdiff.d](https://git.zhirov.kz/dlang/xdiff) for comput
Add to `dub.json`: Add to `dub.json`:
```json
{
"dependencies": {
"sdiff": "~>0.1.0"
}
}
```
Or
```json ```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,6 +31,9 @@ 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 ~ ")");
} }
abstract class MM
{
private:
mmfile_t initMmfile(size_t blockSize) mmfile_t initMmfile(size_t blockSize)
{ {
mmfile_t mf; mmfile_t mf;
@ -38,12 +41,12 @@ mmfile_t initMmfile(size_t blockSize)
enforce(rc == 0, "xdl_init_mmfile failed (rc=" ~ rc.to!string ~ ")"); enforce(rc == 0, "xdl_init_mmfile failed (rc=" ~ rc.to!string ~ ")");
return mf; return mf;
} }
abstract class MM
{
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;