mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-20 20:26:42 +00:00
Simplify buffering and re-use single buffer for registrations and notifications
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31172 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4b837ea36a
commit
25ccbf3885
2 changed files with 17 additions and 12 deletions
|
@ -567,8 +567,8 @@ notify(NSNotificationCenter *center, NSNotificationQueueList *list,
|
|||
NSString *mode, NSZone *zone)
|
||||
{
|
||||
BOOL allocated = NO;
|
||||
NSNotificationQueueRegistration *buf[100];
|
||||
NSNotificationQueueRegistration **ptr = buf;
|
||||
void *buf[100];
|
||||
void **ptr = buf;
|
||||
unsigned len = sizeof(buf) / sizeof(*buf);
|
||||
unsigned pos = 0;
|
||||
NSNotificationQueueRegistration *item = list->head;
|
||||
|
@ -607,24 +607,29 @@ notify(NSNotificationCenter *center, NSNotificationQueueList *list,
|
|||
}
|
||||
len = pos; // Number of items found
|
||||
|
||||
/* Posting a notification catches exceptions, so it's OK to use
|
||||
* retain/release of objects here as we won't get an exception
|
||||
* causing a leak.
|
||||
*/
|
||||
if (len > 0)
|
||||
{
|
||||
NSMutableArray *ma = [NSMutableArray arrayWithCapacity: len];
|
||||
|
||||
for (pos = 0; pos < len; pos++)
|
||||
{
|
||||
item = ptr[pos];
|
||||
[ma addObject: item->notification];
|
||||
ptr[pos] = RETAIN(item->notification);
|
||||
remove_from_queue(list, item, zone);
|
||||
}
|
||||
for (pos = 0; pos < len; pos++)
|
||||
{
|
||||
NSNotification *n = (NSNotification*)ptr[pos];
|
||||
|
||||
[center postNotification: n];
|
||||
RELEASE(n);
|
||||
}
|
||||
if (allocated)
|
||||
{
|
||||
NSZoneFree(NSDefaultMallocZone(), ptr);
|
||||
}
|
||||
for (pos = 0; pos < len; pos++)
|
||||
{
|
||||
[center postNotification: [ma objectAtIndex: pos]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue