mirror of
https://github.com/gnustep/libs-performance.git
synced 2025-02-15 08:00:52 +00:00
Add functions to help with link store
This commit is contained in:
parent
25e60c6301
commit
09dfc1c403
2 changed files with 27 additions and 22 deletions
|
@ -387,6 +387,30 @@ GSLinkedListRemove(GSListLink *link, GSLinkedList *list);
|
|||
|
||||
@end
|
||||
|
||||
static inline void
|
||||
GSLinkStoreConsumeLink(GSLinkStore *list, GSListLink NS_CONSUMED *link)
|
||||
{
|
||||
link->next = list->free;
|
||||
list->free = link;
|
||||
}
|
||||
|
||||
static inline GSListLink* NS_RETURNS_RETAINED
|
||||
GSLinkStoreProvideLink(GSLinkStore *list)
|
||||
{
|
||||
GSListLink *link = list->free;
|
||||
|
||||
if (nil == link)
|
||||
{
|
||||
link = [list->linkClass new];
|
||||
}
|
||||
else
|
||||
{
|
||||
list->free = link->next;
|
||||
link->next = nil;
|
||||
}
|
||||
return link;
|
||||
}
|
||||
|
||||
/** Adds the object to the list after the specified link.<br />
|
||||
* Calls GSLinkedListInsertAfter().<br />
|
||||
* Returns the list link that the object is stored in.
|
||||
|
|
|
@ -618,17 +618,8 @@ GSListLink*
|
|||
GSLinkStoreInsertObjectAfter(
|
||||
NSObject *anObject, GSLinkStore *list, GSListLink *at)
|
||||
{
|
||||
GSListLink *link = list->free;
|
||||
GSListLink *link = GSLinkStoreProvideLink(list);
|
||||
|
||||
if (nil == link)
|
||||
{
|
||||
link = [list->linkClass new];
|
||||
}
|
||||
else
|
||||
{
|
||||
list->free = link->next;
|
||||
link->next = nil;
|
||||
}
|
||||
link->item = RETAIN(anObject);
|
||||
GSLinkedListInsertAfter(link, list, (nil == at) ? list->tail : at);
|
||||
return link;
|
||||
|
@ -638,17 +629,8 @@ GSListLink*
|
|||
GSLinkStoreInsertObjectBefore(
|
||||
NSObject *anObject, GSLinkStore *list, GSListLink *at)
|
||||
{
|
||||
GSListLink *link = list->free;
|
||||
GSListLink *link = GSLinkStoreProvideLink(list);
|
||||
|
||||
if (nil == link)
|
||||
{
|
||||
link = [list->linkClass new];
|
||||
}
|
||||
else
|
||||
{
|
||||
list->free = link->next;
|
||||
link->next = nil;
|
||||
}
|
||||
link->item = RETAIN(anObject);
|
||||
GSLinkedListInsertBefore(link, list, (nil == at) ? list->head : at);
|
||||
return link;
|
||||
|
@ -662,8 +644,7 @@ GSLinkStoreRemoveObjectAt(GSLinkStore *list, GSListLink *at)
|
|||
GSLinkedListRemove(at, list);
|
||||
RELEASE(at->item);
|
||||
at->item = nil;
|
||||
at->next = list->free;
|
||||
list->free = at;
|
||||
GSLinkStoreConsumeLink(list, at);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue