8000 Move GalleySeries from std::list to std::vector · postgrespro/libblobstamper@4a46de2 · GitHub
[go: up one dir, main page]

Skip to content
65F2

Commit 4a46de2

Browse files
Move GalleySeries from std::list to std::vector
1 parent cafc8ce commit 4a46de2

File tree

4 files changed

+36
-75
lines changed

4 files changed

+36
-75
lines changed

blobstamper/galley.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ GalleySeries::minSize()
3131

3232

3333

34-
std::list<std::string>
34+
std::vector<std::string>
3535
GalleySeries::ExtractStr(Blob &blob)
3636
{
37-
std::list<std::string> res;
38-
std::list<Blob> blobs = extract_internal(blob);
37+
std::vector<std::string> res;
38+
std::vector<Blob> blobs = extract_internal(blob);
3939
for(Blob blob : blobs)
4040
{
4141
std::string str= blob.ShiftSingleStampStr(stamp);
@@ -44,11 +44,11 @@ GalleySeries::ExtractStr(Blob &blob)
4444
return res;
4545
}
4646

47-
std::list<std::vector<char>>
47+
std::vector<std::vector<char>>
4848
GalleySeries::ExtractBin(Blob &blob)
4949
{
50-
std::list<std::vector<char>> res;
51-
std::list<Blob> blobs = extract_internal(blob);
50+
std::vector<std::vector<char>> res;
51+
std::vector<Blob> blobs = extract_internal(blob);
5252
for(Blob blob : blobs)
5353
{
5454
std::vector<char> data = blob.ShiftSingleStampBin(stamp);
@@ -57,14 +57,14 @@ GalleySeries::ExtractBin(Blob &blob)
5757
return res;
5858
}
5959

60-
std::list<Blob>
60+
std::vector<Blob>
6161
GalleySeries::extract_internal(Blob &blob)
6262
{
6363
if (blob.Size()<stamp.minSize())
6464
{
6565
throw OutOfData(); /* FIXME: May be later add option that allows empty lists if needed*/
6666
}
67-
std::list<Blob> res;
67+
std::vector<Blob> res;
6868
if (stamp.isFixedSize())
6969
{
7070
int size = stamp.minSize();

blobstamper/galley.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class GalleySeries : public GalleyBase
2828
StampBase &stamp;
2929
public:
3030
GalleySeries(StampBase & stamp_arg) : stamp(stamp_arg) {};
31-
std::list<Blob> extract_internal(Blob &blob);
32-
std::list<std::string> ExtractStr(Blob &blob);
33-
std::list<std::vector<char>> ExtractBin(Blob &blob);
31+
std::vector<Blob> extract_internal(Blob &blob);
32+
std::vector<std::string> ExtractStr(Blob &blob);
33+
std::vector<std::vector<char>> ExtractBin(Blob &blob);
3434

3535
int minSize() override;
3636
int maxSize() override {return -1;}; /* Sereies always takes as much data as it can take */

t/300-galley.cpp

Lines changed: 24 additions & 63 deletions
unsigned short int * data;
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,12 @@ main()
2929
StampTwoChars stamp;
3030
GalleySeries galley(stamp);
3131
Blob blob(short_sample, strlen(short_sample));
32-
std::list<std::string> res = galley.ExtractStr(blob);
33-
34-
std::string str;
35-
36-
str = res.front();
37-
is(str, expected1, "GalleySeries, fixed size string stamp: First element of shifted list is ok");
38-
res.pop_front();
39-
40-
str = res.front();
41-
is(str, expected2, "GalleySeries, fixed size string stamp: Second element of shifted list is ok");
42-
res.pop_front();
43-
44-
str = res.front();
45-
is(str, expected3, "GalleySeries, fixed size string stamp: Third element of shifted list is ok");
46-
res.pop_front();
32+
std::vector<std::string> res = galley.ExtractStr(blob);
4733

48-
ok(res.empty(), "GalleySeries, fixed size string stamp: The rest of the list is empty");
34+
is(res[0], expected1, "GalleySeries, fixed size string stamp: First element of shifted list is ok");
35+
is(res[1], expected2, "GalleySeries, fixed size string stamp: Second element of shifted list is ok");
36+
is(res[2], expected3, "GalleySeries, fixed size string stamp: Third element of shifted list is ok");
37+
is(res.size(), 3, "GalleySeries, fixed size string stamp: res has 3 items");
4938
}
5039
/* Test Galley Sereies with unlimited size stamp*/
5140
{ /* 5 .. 9*/
@@ -61,26 +50,14 @@ main()
6150
StampTwoCharsList stamp_charlist;
6251
GalleySeries galley(stamp_charlist);
6352

64-
std::list<std::string> res = galley.ExtractStr(blob);
53+
std::vector<std::string> res = galley.ExtractStr(blob);
6554
std::string str;
6655

67-
str = res.front();
68-
is(str, expected1, "GalleySeries, unlimited size string stamp: First element of shifted list is ok");
69-
res.pop_front();
70-
71-
str = res.front();
72-
is(str, expected2, "GalleySeries, unlimited size string stamp: Second element of shifted list is ok");
73-
res.pop_front();
74-
75-
str = res.front();
76-
is(str, expected3, "GalleySeries, unlimited size string stamp: Third element of shifted list is ok");
77-
res.pop_front();
78-
79-
str = res.front();
80-
is(str, expected4, "GalleySeries, unlimited size string stamp: Fourth element of shifted list is ok");
81-
res.pop_front();
82-
83-
ok(res.empty(), "GalleySeries, unlimited size string stamp: The rest of the list is empty");
56+
is(res[0], expected1, "GalleySeries, unlimited size string stamp: First element of shifted list is ok");
57+
is(res[1], expected2, "GalleySeries, unlimited size string stamp: Second element of shifted list is ok");
58+
is(res[2], expected3, "GalleySeries, unlimited size string stamp: Third element of shifted list is ok");
59+
is(res[3], expected4, "GalleySeries, unlimited size string stamp: Fourth element of shifted list is ok");
60+
is(res.size(), 4, "GalleySeries, unlimited size string stamp: The rest of the list is empty");
8461
}
8562

8663
{ /* 10..13 */
@@ -92,27 +69,24 @@ main()
9269
StampArithm<unsigned short int> stamp;
9370
GalleySeries galley(stamp);
9471
Blob blob(short_sample, strlen(short_sample));
95-
std::list<std::vector<char>> res = galley.ExtractBin(blob);
72+
std::vector<std::vector<char>> res = galley.ExtractBin(blob);
9673

9774
std::vector<char> v;
9875
9976

100-
v = res.front();
77+
v = res[0];
10178
data = (unsigned short int *) &v[0];
10279
is(*data, expected1, "GalleySeries, fixed size binary stamp: First element of shifted list is ok");
103-
res.pop_front();
10480

105-
v = res.front();
81+
v = res[1];
10682
data = (unsigned short int *) &v[0];
10783
is(*data, expected2, "GalleySeries, fixed size binary stamp: Second element of shifted list is ok");
108-
res.pop_front();
10984

110-
v = res.front();
85+
v = res[2];
11186
data = (unsigned short int *) &v[0];
11287
is(*data, expected3, "GalleySeries, fixed size binary stamp: Third element of shifted list is ok");
113-
res.pop_front();
11488

115-
ok(res.empty(), "GalleySeries, fixed size binary stamp: The rest of the list is empty");
89+
is(res.size(),3, "GalleySeries, fixed size binary stamp: result has 3 elements");
11690
}
11791

11892
/* Test Galley Sereies with variated size stamp*/
@@ -131,26 +105,15 @@ main()
131105
StampSeveralChars stamp;
132106
GalleySeries galley(stamp);
133107

134-
std::list<std::string> res = galley.ExtractStr(blob);
108+
std::vector<std::string> res = galley.ExtractStr(blob);
135109
std::string str;
136110

137-
str = res.front();
138-
is(str, expected1, "GalleySeries, unlimited size string stamp: First element of shifted list is ok");
139-
res.pop_front();
140-
141-
str = res.front();
142-
is(str, expected2, "GalleySeries, unlimited size string stamp: Second element of shifted list is ok");
143-
res.pop_front();
111+
is(res[0], expected1, "GalleySeries, unlimited size string stamp: First element of shifted list is ok");
112+
is(res[1], expected2, "GalleySeries, unlimited size string stamp: Second element of shifted list is ok");
113+
is(res[2], expected3, "GalleySeries, unlimited size string stamp: Third element of shifted list is ok");
114+
is(res[3], expected4, "GalleySeries, unlimited size string stamp: Fourth element of shifted list is ok");
144115

145-
str = res.front();
146-
is(str, expected3, "GalleySeries, unlimited size string stamp: Third element of shifted list is ok");
147-
res.pop_front();
148-
149-
str = res.front();
150-
is(str, expected4, "GalleySeries, unlimited size string stamp: Fourth element of shifted list is ok");
151-
res.pop_front();
152-
153-
ok(res.empty(), "GalleySeries, unlimited size string stamp: The rest of the list is empty");
116+
is(res.size(), 4, "GalleySeries, unlimited size string stamp: The list has only 4 members");
154117

155118
}
156119

@@ -242,11 +205,9 @@ main()
242205
std::vector<std::string> res = galley.ExtractStr(blob);
243206
std::string str;
244207

245-
str = res[0];
246-
is(str, expected1, "GalleySet, unbounded size string stamp: First element of vector is ok");
208+
is(res[0], expected1, "GalleySet, unbounded size string stamp: First element of vector is ok");
247209

248-
str = res[1];
249-
is(str, expected2, "GalleySet, unbounded size string stamp: Second element of vector is ok");
210+
is(res[1], expected2, "GalleySet, unbounded size string stamp: Second element of vector is ok");
250211

251212
is(res.size(), 2, "GalleySet, unbounded size string stamp: The vector has only two elements ");
252213

t/test-chars-stamps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ std::string
8282
StampTwoCharsList::ExtractStr(Blob &blob)
8383
{
8484
std::string res = "";
85-
std::list<std::string> list = galley.ExtractStr(blob);
85+
std::vector<std::string> list = galley.ExtractStr(blob);
8686

8787
for (std::string point : list)
8888
{

0 commit comments

Comments
 (0)
0