1-
21Ideas for refactorings:
32
43- change all size_t => int
@@ -7,142 +6,8 @@ Ideas for refactorings:
76
87------------------------------------------------------------------
98
10- static void ClearPixmap(fz_pixmap* pixmap) {
11- auto stride = pixmap->stride;
12- size_t dx = (size_t)pixmap->w;
13- size_t dy = (size_t)pixmap->h;
14- u8* samples = pixmap->samples;
15- ReportIf(pixmap->n != 3);
16- for (size_t y = 0; y < dy; y++) {
17- u8* d = samples + (stride * y);
18- for (size_t x = 0; x < dx; x++) {
19- d[0] = 255;
20- d[1] = 0;
21- d[2] = 0;
22- d += pixmap->n;
23- if (false) {
24- if (x % 2 == 0) {
25- *d++ = 255;
26- *d++ = 0;
27- *d++ = 0;
28- } else {
29- *d++ = 0;
30- *d++ = 0;
31- *d++ = 255;
32- }
33- }
34- }
35- }
36- }
37-
38- ------------------------------------------------------------------
39-
40- // Select random files to test. We want to test each file type equally, so
41- // we first group them by file extension and then select up to maxPerType
42- // for each extension, randomly, and inter-leave the files with different
43- // extensions, so their testing is evenly distributed.
44- // Returns result in <files>.
45- static void RandomizeFiles(StrVec& files, int maxPerType) {
46- StrVec fileExts;
47- Vec<StrVec*> filesPerType;
48-
49- for (int i = 0; i < files.Size(); i++) {
50- char* file = files.at(i);
51- char* ext = path::GetExtTemp(file);
52- CrashAlwaysIf(!ext);
53- int typeNo = fileExts.FindI(ext);
54- if (-1 == typeNo) {
55- fileExts.Append(ext);
56- filesPerType.Append(new StrVec());
57- typeNo = filesPerType.Size() - 1;
58- }
59- filesPerType.at(typeNo)->Append(file);
60- }
61-
62- for (size_t j = 0; j < filesPerType.size(); j++) {
63- StrVec* all = filesPerType.at(j);
64- StrVec* random = new StrVec();
65-
66- for (int n = 0; n < maxPerType && all->Size() > 0; n++) {
67- int idx = rand() % all->Size();
68- char* file = all->at(idx);
69- random->Append(file);
70- all->RemoveAt(idx);
71- }
72-
73- filesPerType.at(j) = random;
74- delete all;
75- }
76-
77- files.Reset();
78-
79- bool gotAll = false;
80- while (!gotAll) {
81- gotAll = true;
82- for (size_t j = 0; j < filesPerType.size(); j++) {
83- StrVec* random = filesPerType.at(j);
84- if (random->Size() > 0) {
85- gotAll = false;
86- char* file = random->at(0);
87- files.Append(file);
88- random->RemoveAt(0);
89- }
90- }
91- }
92-
93- for (size_t j = 0; j < filesPerType.size(); j++) {
94- delete filesPerType.at(j);
95- }
96- }
97-
98- ------------------------------------------------------------------
99-
1009StrVec2 ideas:
10110- optimize for SetAt(): when removing last string from a page, free its memory (update currEnd)
10211- implement StrVec2::InsertAt()
10312
10413------------------------------------------------------------------
105-
106- struct ClosureData;
107- typedef void (*closureFunc)(ClosureData*);
108-
109- struct ClosureData {
110- closureFunc func;
111- virtual ~ClosureData() = 0;
112- virtual operator()() {
113- func(this);
114- }
115- };
116-
117- template <typename T>
118- ClosureData* newClosure(void (*func)(T*)) {
119- T* res = new T();
120- res->func = (closureFunc)func;
121- return res;
122- }
123-
124- struct UpdateCheckData : ClosureData {
125- ~UpdateCheckData() override {
126- }
127- };
128-
129- void updateCheck(UpdateCheckData* d) {
130- // ...
131- delete d;
132- }
133-
134- auto res = newClosure<UpdateCheckData>(updateCheck);
135-
136- ------------------------------------------------------------------
137-
138- Delegates ideas:
139- https://github.com/rosbacke/delegate
140- https://github.com/rosbacke/MCU-tools/tree/master/src/callback
141- https://github.com/Naios/function2
142- https://gist.github.com/twoscomplement/030818a6c38c5a983482dc3a385a3ab8
143- https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0792r3.html
144- https://github.com/vittorioromeo/Experiments/blob/master/function_ref.cpp
145- https://blog.stratifylabs.dev/device/2022-12-01-Callback-and-Lambdas-in-embedded-cpp/
146-
147- CmdOpenAttachment,,Open Attachment,ver 3.6+
148- CmdSaveAttachment,,Save Attachment,ver 3.6+
0 commit comments