File tree Expand file tree Collapse file tree 2 files changed +8
-24
lines changed Expand file tree Collapse file tree 2 files changed +8
-24
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
10
10
* ` release-new-version.sh ` script
11
11
12
12
### Changed
13
+ * Shortened ` ArduinoQueue ` push and pop operations
13
14
14
15
### Deprecated
15
16
16
17
### Removed
17
18
18
19
### Fixed
20
+ * ` ArduinoQueue ` no longer leaks memory
19
21
20
22
### Security
21
23
Original file line number Diff line number Diff line change @@ -27,44 +27,26 @@ class ArduinoCIQueue {
27
27
}
28
28
29
29
inline unsigned long size () const { return mSize ; }
30
-
31
30
inline bool empty () const { return 0 == mSize ; }
32
-
33
31
T front () const { return empty () ? mNil : mFront ->data ; }
34
-
35
32
T back () const { return empty () ? mNil : mBack ->data ; }
36
33
37
34
bool push (const T& v)
38
35
{
39
36
Node *n = new Node;
40
37
if (n == NULL ) return false ;
41
-
42
38
n->data = v;
43
39
n->next = NULL ;
44
-
45
- if (mFront == NULL )
46
- {
47
- mFront = mBack = n;
48
- } else {
49
- mBack ->next = n;
50
- mBack = n;
51
- }
52
-
53
- ++mSize ;
54
- return true ;
40
+ mBack = (mFront == NULL ? mFront : mBack ->next ) = n;
41
+ return ++mSize ;
55
42
}
56
43
57
44
void pop () {
58
45
if (empty ()) return ;
59
- if (mFront == mBack ) {
60
- mFront = mBack = NULL ;
61
- } else {
62
- Node* n = mFront ;
63
- mFront = mFront ->next ;
64
- delete n;
65
- }
66
-
67
- --mSize ;
46
+ Node* n = mFront ;
47
+ mFront = mFront ->next ;
48
+ delete n;
49
+ if (--mSize ) mBack = NULL ;
68
50
}
69
51
70
52
void clear () { while (!empty ()) pop (); }
You can’t perform that action at this time.
0 commit comments