@@ -11,13 +11,9 @@ void NotificationManager::Push(NotificationManager::Notification&& notif) {
1111 notif.id = GetNextId ();
1212 notif.valid = true ;
1313 newNotification = true ;
14- if (beginIdx > 0 ) {
15- --beginIdx;
16- } else {
17- beginIdx = notifications.size () - 1 ;
18- }
19- notifications[beginIdx] = std::move (notif);
20- if (size < notifications.size ()) {
14+ notifications--;
15+ notifications[0 ] = std::move (notif);
16+ if (size < notifications.Size ()) {
2117 size++;
2218 }
2319}
@@ -30,30 +26,12 @@ NotificationManager::Notification NotificationManager::GetLastNotification() con
3026 if (this ->IsEmpty ()) {
3127 return {};
3228 }
33- return this ->At (0 );
34- }
35-
36- const NotificationManager::Notification& NotificationManager::At (NotificationManager::Notification::Idx idx) const {
37- if (idx >= notifications.size ()) {
38- assert (false );
39- return notifications.at (beginIdx); // this should not happen
40- }
41- size_t read_idx = (beginIdx + idx) % notifications.size ();
42- return notifications.at (read_idx);
43- }
44-
45- NotificationManager::Notification& NotificationManager::At (NotificationManager::Notification::Idx idx) {
46- if (idx >= notifications.size ()) {
47- assert (false );
48- return notifications.at (beginIdx); // this should not happen
49- }
50- size_t read_idx = (beginIdx + idx) % notifications.size ();
51- return notifications.at (read_idx);
29+ return notifications[0 ];
5230}
5331
5432NotificationManager::Notification::Idx NotificationManager::IndexOf (NotificationManager::Notification::Id id) const {
5533 for (NotificationManager::Notification::Idx idx = 0 ; idx < this ->size ; idx++) {
56- const NotificationManager::Notification& notification = this -> At ( idx) ;
34+ const NotificationManager::Notification& notification = notifications[ idx] ;
5735 if (notification.id == id) {
5836 return idx;
5937 }
@@ -66,29 +44,29 @@ NotificationManager::Notification NotificationManager::Get(NotificationManager::
6644 if (idx == this ->size ) {
6745 return {};
6846 }
69- return this -> At ( idx) ;
47+ return notifications[ idx] ;
7048}
7149
7250NotificationManager::Notification NotificationManager::GetNext (NotificationManager::Notification::Id id) const {
7351 NotificationManager::Notification::Idx idx = this ->IndexOf (id);
7452 if (idx == this ->size ) {
7553 return {};
7654 }
77- if (idx == 0 || idx > notifications.size ()) {
55+ if (idx == 0 || idx > notifications.Size ()) {
7856 return {};
7957 }
80- return this -> At ( idx - 1 ) ;
58+ return notifications[ idx - 1 ] ;
8159}
8260
8361NotificationManager::Notification NotificationManager::GetPrevious (NotificationManager::Notification::Id id) const {
8462 NotificationManager::Notification::Idx idx = this ->IndexOf (id);
8563 if (idx == this ->size ) {
8664 return {};
8765 }
88- if (static_cast < size_t >( idx + 1 ) >= notifications.size ()) {
66+ if (idx + 1u >= notifications.Size ()) {
8967 return {};
9068 }
91- return this -> At ( idx + 1 ) ;
69+ return notifications[ idx + 1 ] ;
9270}
9371
9472void NotificationManager::DismissIdx (NotificationManager::Notification::Idx idx) {
@@ -100,14 +78,14 @@ void NotificationManager::DismissIdx(NotificationManager::Notification::Idx idx)
10078 return ; // this should not happen
10179 }
10280 if (idx == 0 ) { // just remove the first element, don't need to change the other elements
103- notifications. at (beginIdx) .valid = false ;
104- beginIdx = (beginIdx + 1 ) % notifications. size () ;
81+ notifications[ 0 ] .valid = false ;
82+ notifications++ ;
10583 } else {
10684 // overwrite the specified entry by moving all later messages one index to the front
10785 for (size_t i = idx; i < size - 1 ; ++i) {
108- this -> At (i) = this -> At ( i + 1 ) ;
86+ notifications[i] = notifications[ i + 1 ] ;
10987 }
110- this -> At ( size - 1 ) .valid = false ;
88+ notifications[ size - 1 ] .valid = false ;
11189 }
11290 --size;
11391}
0 commit comments