Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita3413df

Browse files
Get rid of StampFixed base class. It makes code more comples, instead of making it more simple
1 parente42555e commita3413df

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

‎blobstamper/stamp.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
22
*
3-
* Copyright 2021 Nikolay Shaplov (Postgres Professional)
3+
* Copyright 2021-2023 Nikolay Shaplov (Postgres Professional)
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -107,15 +107,6 @@ StampBaseV<T>::ExtractBin(Blob &blob)
107107
return v;
108108
}
109109

110-
classStampFixed :publicvirtual StampBase
111-
{
112-
protected:
113-
int size;
114-
public:
115-
virtualintminSize()override {return size;}
116-
virtualintmaxSize()override {return size;}
117-
};
118-
119110
classStampVariated :publicvirtual StampBase
120111
{
121112
protected:

‎blobstamper/stamp_arithm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
#include"helpers.h"
2424
#include"stamp.h"
2525

26-
template<classT>classStampArithm:publicStampFixed,publicStampBaseStr,publicStampBaseV<T>
26+
template<classT>classStampArithm:publicStampBaseStr,publicStampBaseV<T>
2727
{
2828
public:
29-
StampArithm() { size =sizeof(T);};
29+
virtualintminSize()override {returnsizeof(T);}
30+
virtualintmaxSize()override {returnsizeof(T);}
3031
virtual std::stringExtractStr(Blob &blob)override;
3132
virtual TExtractValue(Blob &blob)override;
3233
};

‎blobstamper/stamp_dict.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include"stamp_arithm.h"
2727
#include"dict.h"
2828

29-
classStampDict:publicStampFixed,publicStampBaseStr
29+
classStampDict:publicStampBaseStr
3030
{
3131
protected:
3232
StampArithm<unsignedchar> stamp8;

‎t/test-chars-stamps.h

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
22
*
3-
* Copyright 2021 Nikolay Shaplov (Postgres Professional)
3+
* Copyright 2021-2023 Nikolay Shaplov (Postgres Professional)
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -19,39 +19,35 @@
1919
/* This stamps chops first two bytes and treat them as string*/
2020
/* Never do this in real live, as blob is binary and may have \0 in the middle of it*/
2121

22-
classStampTwoChars:publicStampFixed,publicStampBaseStr
22+
classStampTwoChars:publicStampBaseStr
2323
{
2424
public:
25-
StampTwoChars();
2625
std::stringExtractStr(Blob &blob)override;
27-
};
26+
virtualintminSize()override {return2;}/* This stamp shifts two characters only*/
27+
virtualintmaxSize()override {return2;}/* This stamp shifts two characters only*/
2828

29-
StampTwoChars::StampTwoChars() : StampFixed()
30-
{
31-
size =2;/* This stamp shifts two characters only*/
32-
}
29+
};
3330

3431
std::string
3532
StampTwoChars::ExtractStr(Blob &blob)
3633
{
37-
char * buf;
38-
size_t buf_size;
34+
/* Chopping suitable data chunk from blob*/
35+
std::vector<char> data = blob.ChopBlank(*this);
3936

40-
Blob blob2 = blob.ShiftBytes(size);
41-
if (blob2.isEmpty())
42-
return"";
37+
size_t buf_size = data.size() +1;
38+
char * buf = (char *)malloc(buf_size);
39+
memcpy(buf, &data[0], data.size());
40+
buf[buf_size-1] ='\0';
4341

4442
/* Save shited data as string*/
4543
/* NEVER do this in prod, as in real live blob is binary and may have 0 in the middle of it*/
46-
blob2.DataDup(buf, buf_size);
47-
buf = (char *)realloc((void *)buf, buf_size +1);
48-
buf[buf_size] ='\0';
4944
std::string res = buf;
5045
free(buf);
5146

5247
return res;
5348
}
5449

50+
/*****************************************************************************/
5551
classStampSeveralChars:publicStampVariated,publicStampBaseStr
5652
{
5753
public:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp