File tree Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ Get the item at the front of the queue.
39
39
"""
40
40
@inline function first (D:: CircularDeque )
41
41
@boundscheck D. n > 0 || throw (BoundsError ())
42
- return D. buffer[D. first]
42
+ return @inbounds D. buffer[D. first]
43
43
end
44
44
45
45
"""
@@ -49,7 +49,7 @@ Get the item from the back of the queue.
49
49
"""
50
50
@inline function last (D:: CircularDeque )
51
51
@boundscheck D. n > 0 || throw (BoundsError ())
52
- return D. buffer[D. last]
52
+ return @inbounds D. buffer[D. last]
53
53
end
54
54
55
55
@inline function Base. push! (D:: CircularDeque , v)
61
61
return D
62
62
end
63
63
64
- @inline function Base. pop! (D:: CircularDeque )
64
+ @inline Base . @propagate_inbounds function Base. pop! (D:: CircularDeque )
65
65
v = last (D)
66
66
D. n -= 1
67
67
tmp = D. last - 1
88
88
89
89
Remove the element at the front.
90
90
"""
91
- @inline function popfirst! (D:: CircularDeque )
91
+ @inline Base . @propagate_inbounds function popfirst! (D:: CircularDeque )
92
92
v = first (D)
93
93
D. n -= 1
94
94
tmp = D. first + 1
Original file line number Diff line number Diff line change 69
69
Remove the element at the back.
70
70
"""
71
71
@inline function Base. pop! (cb:: CircularBuffer )
72
- (cb. length == 0 ) && throw (ArgumentError (" array must be non-empty" ))
72
+ @boundscheck (cb. length == 0 ) && throw (ArgumentError (" array must be non-empty" ))
73
73
i = _buffer_index (cb, cb. length)
74
74
cb. length -= 1
75
- return cb. buffer[i]
75
+ return @inbounds cb. buffer[i]
76
76
end
77
77
78
78
"""
@@ -87,7 +87,7 @@ Add an element to the back and overwrite front if full.
87
87
else
88
88
cb. length += 1
89
89
end
90
- cb. buffer[_buffer_index (cb, cb. length)] = data
90
+ @inbounds cb. buffer[_buffer_index (cb, cb. length)] = data
91
91
return cb
92
92
end
93
93
97
97
Remove the element from the front of the `CircularBuffer`.
98
98
"""
99
99
function popfirst! (cb:: CircularBuffer )
100
- if cb. length == 0
101
- throw (ArgumentError (" array must be non-empty" ))
102
- end
100
+ @boundscheck (cb. length == 0 ) && throw (ArgumentError (" array must be non-empty" ))
103
101
i = cb. first
104
102
cb. first = (cb. first + 1 > cb. capacity ? 1 : cb. first + 1 )
105
103
cb. length -= 1
106
- return cb. buffer[i]
104
+ return @inbounds cb. buffer[i]
107
105
end
108
106
109
107
"""
@@ -118,7 +116,7 @@ function pushfirst!(cb::CircularBuffer, data)
118
116
if length (cb) < cb. capacity
119
117
cb. length += 1
120
118
end
121
- cb. buffer[cb. first] = data
119
+ @inbounds cb. buffer[cb. first] = data
122
120
return cb
123
121
end
124
122
You can’t perform that action at this time.
0 commit comments