Skip to content

Commit 14766b1

Browse files
authored
Merge pull request #16 from SergeyMakeev/perf_improvments
move to github actions
2 parents b99119a + 09080e7 commit 14766b1

File tree

17 files changed

+1076
-121
lines changed

17 files changed

+1076
-121
lines changed

.cursor/rules/ascii.mdc

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
alwaysApply: true
3+
---
4+
5+
# Cursor Rules for LargeCoordinates Project
6+
7+
## Character Encoding Rules
8+
- **NEVER use non-ASCII characters in code**: All code files (*.h, *.cpp, *.c, etc.) must use only ASCII characters (0x00-0x7F)
9+
- **Replace special symbols with ASCII equivalents**:
10+
- Use `+/-` instead of plus-minus symbol
11+
- Use `->` instead of arrow symbols
12+
- Use `<=` instead of less-than-or-equal symbol
13+
- Use `>=` instead of greater-than-or-equal symbol
14+
- Use `!=` instead of not-equal symbol
15+
- Use `*` instead of multiplication symbol
16+
- Use `/` instead of division symbol
17+
- Use `deg` instead of degree symbol
18+
- Use `alpha`, `beta`, `gamma` instead of Greek letters
19+
20+
## Code Style Consistency
21+
- Use standard ASCII punctuation and operators
22+
- Avoid Unicode quotes, dashes, or mathematical symbols
23+
- When documenting mathematical concepts, use ASCII representations
24+
- Comments should use plain ASCII text only
25+
26+
## Examples
27+
28+
### BAD (non-ASCII):
29+
```cpp
30+
// Coordinate range: +/-1024 units (using plus-minus symbol)
31+
// Temperature: 25 deg C (using degree symbol)
32+
// Angle: pi/4 radians (using pi symbol)
33+
float value = alpha * beta; (using Greek letters)
34+
```
35+
36+
### GOOD (ASCII only):
37+
```cpp
38+
// Coordinate range: +/-1024 units
39+
// Temperature: 25 deg C
40+
// Angle: pi/4 radians
41+
float value = alpha * beta;
42+
```
43+
44+
## Enforcement
45+
- All code must pass ASCII-only validation
46+
- Use regex `[^\x00-\x7F]` to detect non-ASCII characters
47+
- Build scripts should reject files containing non-ASCII characters # Cursor Rules for LargeCoordinates Project
48+
49+
## Character Encoding Rules
50+
- **NEVER use non-ASCII characters in code**: All code files (*.h, *.cpp, *.c, etc.) must use only ASCII characters (0x00-0x7F)
51+
- **Replace special symbols with ASCII equivalents**:
52+
- Use `+/-` instead of plus-minus symbol
53+
- Use `->` instead of arrow symbols
54+
- Use `<=` instead of less-than-or-equal symbol
55+
- Use `>=` instead of greater-than-or-equal symbol
56+
- Use `!=` instead of not-equal symbol
57+
- Use `*` instead of multiplication symbol
58+
- Use `/` instead of division symbol
59+
- Use `deg` instead of degree symbol
60+
- Use `alpha`, `beta`, `gamma` instead of Greek letters
61+
62+
## Code Style Consistency
63+
- Use standard ASCII punctuation and operators
64+
- Avoid Unicode quotes, dashes, or mathematical symbols
65+
- When documenting mathematical concepts, use ASCII representations
66+
- Comments should use plain ASCII text only
67+
68+
## Examples
69+
70+
### BAD (non-ASCII):
71+
```cpp
72+
// Coordinate range: +/-1024 units (using plus-minus symbol)
73+
// Temperature: 25 deg C (using degree symbol)
74+
// Angle: pi/4 radians (using pi symbol)
75+
float value = alpha * beta; (using Greek letters)
76+
```
77+
78+
### GOOD (ASCII only):
79+
```cpp
80+
// Coordinate range: +/-1024 units
81+
// Temperature: 25 deg C
82+
// Angle: pi/4 radians
83+
float value = alpha * beta;
84+
```
85+
86+
## Enforcement
87+
- All code must pass ASCII-only validation
88+
- Use regex `[^\x00-\x7F]` to detect non-ASCII characters
89+
- Build scripts should reject files containing non-ASCII characters

.cursor/rules/coding_style.mdc

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
---
2+
alwaysApply: true
3+
---
4+
5+
6+
# Coding Style Rules
7+
8+
## Documentation and Communication
9+
- **No diagrams**: Do not create Mermaid diagrams unless explicitly requested
10+
- **Concise summaries**: Keep explanations brief and focused
11+
- **No verbose documentation**: Avoid lengthy explanations of obvious concepts
12+
13+
## Code Comments
14+
- **Minimal commenting**: Only comment tricky or non-obvious code
15+
- **No redundant comments**: Don't explain what the code obviously does
16+
- **Focus on why, not what**: When commenting, explain reasoning rather than mechanics
17+
18+
## Code Duplication Elimination
19+
- **Use template metaprogramming**: Eliminate duplication with templates rather than copying similar classes
20+
- **Template parameters for behavior**: When applicable use bool template parameters to control const/non-const variants
21+
- **Type aliases for clean APIs**: Provide familiar names while using unified implementations
22+
- **Follow standard library patterns**: Use patterns like `std::conditional_t` and SFINAE for type safety
23+
- **Single source of truth**: Maintain logic in one place to reduce maintenance burden
24+
25+
## Control Flow and Nesting
26+
- **Prefer early exits**: Use guard clauses and early returns to minimize nesting
27+
- **Avoid deep conditionals**: Keep the main logic at the top level rather than buried in if statements
28+
- **Handle edge cases first**: Deal with special cases early and return, leaving the main path unindented
29+
- **Linear flow**: Structure code so the primary logic flows top-to-bottom without deep nesting
30+
31+
## Examples
32+
33+
### ❌ Bad (over-commented):
34+
```cpp
35+
// Increment the size member variable
36+
++m_size;
37+
38+
// Loop through all fields
39+
for (size_t i = 0; i < num_fields; ++i) {
40+
// Calculate the field offset
41+
layout.field_offsets[i] = layout.total_size;
42+
}
43+
```
44+
45+
### ✅ Good (minimal comments):
46+
```cpp
47+
++m_size;
48+
49+
for (size_t i = 0; i < num_fields; ++i) {
50+
layout.field_offsets[i] = layout.total_size;
51+
layout.total_size += capacity * s_field_layout.element_sizes[i];
52+
// Align for optimal cache performance
53+
layout.total_size = (layout.total_size + CPU_CACHE_LINE_SIZE - 1) & ~(CPU_CACHE_LINE_SIZE - 1);
54+
}
55+
```
56+
57+
### ❌ Bad (duplicated iterator classes):
58+
```cpp
59+
class my_iterator {
60+
T* current_;
61+
// ... 50 lines of iterator implementation
62+
};
63+
64+
class my_const_iterator {
65+
const T* current_;
66+
// ... 50 lines of nearly identical iterator implementation
67+
};
68+
```
69+
70+
### ✅ Good (unified template implementation):
71+
```cpp
72+
template<bool IsConst>
73+
class my_iterator_impl {
74+
using pointer = std::conditional_t<IsConst, const T*, T*>;
75+
using reference = std::conditional_t<IsConst, const T&, T&>;
76+
77+
pointer current_;
78+
// ... single implementation that works for both cases
79+
80+
// Allow non-const to const conversion
81+
template<bool OtherIsConst, typename = std::enable_if_t<IsConst && !OtherIsConst>>
82+
my_iterator_impl(const my_iterator_impl<OtherIsConst>& other) : current_(other.current_) {}
83+
};
84+
85+
// Clean API through type aliases
86+
using my_iterator = my_iterator_impl<false>;
87+
using my_const_iterator = my_iterator_impl<true>;
88+
```
89+
90+
### ❌ Bad (deep nesting):
91+
```cpp
92+
list_node(list_node&& other) noexcept
93+
{
94+
if (other.is_linked())
95+
{
96+
// Take over the other node's position in the list
97+
next_ = other.next_;
98+
prev_ = other.prev_;
99+
100+
// In a circular list, linked nodes are guaranteed to have valid pointers when the node is linked
101+
assert(next_ != nullptr && prev_ != nullptr);
102+
next_->prev_ = this;
103+
prev_->next_ = this;
104+
105+
// Leave other node in unlinked state
106+
other.next_ = nullptr;
107+
other.prev_ = nullptr;
108+
}
109+
}
110+
```
111+
112+
### ✅ Good (early exit, linear flow):
113+
```cpp
114+
list_node(list_node&& other) noexcept
115+
{
116+
if (!other.is_linked())
117+
{
118+
return;
119+
}
120+
121+
// Take over the other node's position in the list
122+
next_ = other.next_;
123+
prev_ = other.prev_;
124+
125+
// In a circular list, linked nodes are guaranteed to have valid pointers when the node is linked
126+
assert(next_ != nullptr && prev_ != nullptr);
127+
next_->prev_ = this;
128+
prev_->next_ = this;
129+
130+
// Leave other node in unlinked state
131+
other.next_ = nullptr;
132+
other.prev_ = nullptr;
133+
}
134+
```
135+
# Coding Style Rules
136+
137+
## Documentation and Communication
138+
- **No diagrams**: Do not create Mermaid diagrams unless explicitly requested
139+
- **Concise summaries**: Keep explanations brief and focused
140+
- **No verbose documentation**: Avoid lengthy explanations of obvious concepts
141+
142+
## Code Comments
143+
- **Minimal commenting**: Only comment tricky or non-obvious code
144+
- **No redundant comments**: Don't explain what the code obviously does
145+
- **Focus on why, not what**: When commenting, explain reasoning rather than mechanics
146+
147+
## Code Duplication Elimination
148+
- **Use template metaprogramming**: Eliminate duplication with templates rather than copying similar classes
149+
- **Template parameters for behavior**: When applicable use bool template parameters to control const/non-const variants
150+
- **Type aliases for clean APIs**: Provide familiar names while using unified implementations
151+
- **Follow standard library patterns**: Use patterns like `std::conditional_t` and SFINAE for type safety
152+
- **Single source of truth**: Maintain logic in one place to reduce maintenance burden
153+
154+
## Control Flow and Nesting
155+
- **Prefer early exits**: Use guard clauses and early returns to minimize nesting
156+
- **Avoid deep conditionals**: Keep the main logic at the top level rather than buried in if statements
157+
- **Handle edge cases first**: Deal with special cases early and return, leaving the main path unindented
158+
- **Linear flow**: Structure code so the primary logic flows top-to-bottom without deep nesting
159+
160+
## Examples
161+
162+
### ❌ Bad (over-commented):
163+
```cpp
164+
// Increment the size member variable
165+
++m_size;
166+
167+
// Loop through all fields
168+
for (size_t i = 0; i < num_fields; ++i) {
169+
// Calculate the field offset
170+
layout.field_offsets[i] = layout.total_size;
171+
}
172+
```
173+
174+
### ✅ Good (minimal comments):
175+
```cpp
176+
++m_size;
177+
178+
for (size_t i = 0; i < num_fields; ++i) {
179+
layout.field_offsets[i] = layout.total_size;
180+
layout.total_size += capacity * s_field_layout.element_sizes[i];
181+
// Align for optimal cache performance
182+
layout.total_size = (layout.total_size + CPU_CACHE_LINE_SIZE - 1) & ~(CPU_CACHE_LINE_SIZE - 1);
183+
}
184+
```
185+
186+
### ❌ Bad (duplicated iterator classes):
187+
```cpp
188+
class my_iterator {
189+
T* current_;
190+
// ... 50 lines of iterator implementation
191+
};
192+
193+
class my_const_iterator {
194+
const T* current_;
195+
// ... 50 lines of nearly identical iterator implementation
196+
};
197+
```
198+
199+
### ✅ Good (unified template implementation):
200+
```cpp
201+
template<bool IsConst>
202+
class my_iterator_impl {
203+
using pointer = std::conditional_t<IsConst, const T*, T*>;
204+
using reference = std::conditional_t<IsConst, const T&, T&>;
205+
206+
pointer current_;
207+
// ... single implementation that works for both cases
208+
209+
// Allow non-const to const conversion
210+
template<bool OtherIsConst, typename = std::enable_if_t<IsConst && !OtherIsConst>>
211+
my_iterator_impl(const my_iterator_impl<OtherIsConst>& other) : current_(other.current_) {}
212+
};
213+
214+
// Clean API through type aliases
215+
using my_iterator = my_iterator_impl<false>;
216+
using my_const_iterator = my_iterator_impl<true>;
217+
```
218+
219+
### ❌ Bad (deep nesting):
220+
```cpp
221+
list_node(list_node&& other) noexcept
222+
{
223+
if (other.is_linked())
224+
{
225+
// Take over the other node's position in the list
226+
next_ = other.next_;
227+
prev_ = other.prev_;
228+
229+
// In a circular list, linked nodes are guaranteed to have valid pointers when the node is linked
230+
assert(next_ != nullptr && prev_ != nullptr);
231+
next_->prev_ = this;
232+
prev_->next_ = this;
233+
234+
// Leave other node in unlinked state
235+
other.next_ = nullptr;
236+
other.prev_ = nullptr;
237+
}
238+
}
239+
```
240+
241+
### ✅ Good (early exit, linear flow):
242+
```cpp
243+
list_node(list_node&& other) noexcept
244+
{
245+
if (!other.is_linked())
246+
{
247+
return;
248+
}
249+
250+
// Take over the other node's position in the list
251+
next_ = other.next_;
252+
prev_ = other.prev_;
253+
254+
// In a circular list, linked nodes are guaranteed to have valid pointers when the node is linked
255+
assert(next_ != nullptr && prev_ != nullptr);
256+
next_->prev_ = this;
257+
prev_->next_ = this;
258+
259+
// Leave other node in unlinked state
260+
other.next_ = nullptr;
261+
other.prev_ = nullptr;
262+
}
263+
```

0 commit comments

Comments
 (0)