Commit 73d57811 authored by darin's avatar darin
Browse files

One more pass of refinement on that last change.

        * History.subproj/WebBackForwardList.m: (-[WebBackForwardList addEntry:]):
	Replace the last entry instead of just ignoring if this one matches.

        * History.subproj/WebHistoryList.h: Add replaceEntryAtIndex. Remove addURL: and removeURL:.

        * History.subproj/WebHistoryList.m:
        (-[WebHistoryList addEntry:]): Call removeEntry: rather than using an entire pasted copy here.
        (-[WebHistoryList removeEntry:]): Use a hash of the URL and the URL rather than relying on the
	fact that WebHistoryItem hashes and does isEqual based on the URL only.
        (-[WebHistoryList replaceEntryAtIndex:withEntry:]): Added. Used by the code above.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@1966 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 64e13709
2002-09-04 Darin Adler <darin@apple.com>
One more pass of refinement on that last change.
* History.subproj/WebBackForwardList.m: (-[WebBackForwardList addEntry:]):
Replace the last entry instead of just ignoring if this one matches.
* History.subproj/WebHistoryList.h: Add replaceEntryAtIndex. Remove addURL: and removeURL:.
* History.subproj/WebHistoryList.m:
(-[WebHistoryList addEntry:]): Call removeEntry: rather than using an entire pasted copy here.
(-[WebHistoryList removeEntry:]): Use a hash of the URL and the URL rather than relying on the
fact that WebHistoryItem hashes and does isEqual based on the URL only.
(-[WebHistoryList replaceEntryAtIndex:withEntry:]): Added. Used by the code above.
2002-09-04 Darin Adler <darin@apple.com>
Fix bug where doing a reload adds an entry to the back/forward list.
......
2002-09-04 Darin Adler <darin@apple.com>
One more pass of refinement on that last change.
* History.subproj/WebBackForwardList.m: (-[WebBackForwardList addEntry:]):
Replace the last entry instead of just ignoring if this one matches.
* History.subproj/WebHistoryList.h: Add replaceEntryAtIndex. Remove addURL: and removeURL:.
* History.subproj/WebHistoryList.m:
(-[WebHistoryList addEntry:]): Call removeEntry: rather than using an entire pasted copy here.
(-[WebHistoryList removeEntry:]): Use a hash of the URL and the URL rather than relying on the
fact that WebHistoryItem hashes and does isEqual based on the URL only.
(-[WebHistoryList replaceEntryAtIndex:withEntry:]): Added. Used by the code above.
2002-09-04 Darin Adler <darin@apple.com>
Fix bug where doing a reload adds an entry to the back/forward list.
......
......@@ -35,13 +35,14 @@ -(void)dealloc
-(void)addEntry:(WebHistoryItem *)entry
{
// If the last entry matches this new entry, don't add a new one, since we are
// presumably just doing a reload.
// If the last entry matches this new entry, then replace it rather than adding
// a new one, since we are doing a reload.
if ([uriList count] > index) {
WebHistoryItem *lastEntry = [uriList entryAtIndex:index];
if ([[lastEntry URL] isEqual:[entry URL]]
&& ([lastEntry target] == [entry target] || [[lastEntry target] isEqual:[entry target]])
&& ([lastEntry parent] == [entry parent] || [[lastEntry parent] isEqual:[entry parent]])) {
[uriList replaceEntryAtIndex:index withEntry:entry];
return;
}
}
......
......@@ -27,14 +27,15 @@ typedef struct WebHistoryListNode WebHistoryListNode;
-(int)maximumSize;
-(void)setMaximumSize:(int)size;
-(WebHistoryItem *)addURL:(NSURL *)URL withTitle:(NSString *)title;
-(WebHistoryItem *)entryAtIndex:(int)index;
-(WebHistoryItem *)entryForURL:(NSURL *)URL;
-(void)addEntry:(WebHistoryItem *)entry;
-(WebHistoryItem *)removeURL:(NSURL *)URL;
-(BOOL)removeEntry:(WebHistoryItem *)entry;
-(WebHistoryItem *)entryForURL:(NSURL *)URL;
-(WebHistoryItem *)entryAtIndex:(int)index;
-(void)removeEntry:(WebHistoryItem *)entry;
-(WebHistoryItem *)removeEntryAtIndex:(int)index;
-(void)removeEntriesToIndex:(int)index;
-(void)replaceEntryAtIndex:(int)index withEntry:(WebHistoryItem *)entry;
@end
......@@ -32,10 +32,10 @@
static void freeNode(WebHistoryListNode *node)
{
// it is important to autorelase here rather than using
// It is important to autorelase here rather than using
// a straight release since we often return an entry
// as a result of an operation that causes a node
// to be freed
// to be freed.
[node->entry autorelease];
free(node);
}
......@@ -100,55 +100,16 @@ -(void)setMaximumSize:(int)size
_maximumSize = size;
}
-(WebHistoryItem *)addURL:(NSURL *)URL withTitle:(NSString *)title;
{
WebHistoryItem *result;
result = [[WebHistoryItem alloc] initWithURL:URL title:title];
[self addEntry:result];
return result;
}
-(void)addEntry:(WebHistoryItem *)entry
{
WebHistoryListNode *node;
unsigned hash;
if (!_allowsDuplicates) {
// search the list first and remove any entry with the same URL
// having the same title does not count
// use the hash codes of the URLs to speed up the linear search
hash = [entry hash];
for (node = _head; node != nil; node = node->next) {
if (hash == node->hash && [entry isEqual:node->entry]) {
_count--;
if (node == _head) {
_head = node->next;
if (_head) {
_head->prev = nil;
}
}
else if (node == _tail) {
_tail = node->prev;
if (_tail) {
_tail->next = nil;
}
}
else {
node->prev->next = node->next;
node->next->prev = node->prev;
}
freeNode(node);
break;
}
}
[self removeEntry:entry];
}
// make new entry and put it at the head of the list
node = newURIListNode(entry);
WebHistoryListNode *node = newURIListNode(entry);
node->next = _head;
_head = node;
_count++;
......@@ -166,15 +127,13 @@ -(void)addEntry:(WebHistoryItem *)entry
}
}
-(WebHistoryItem *)removeURL:(NSURL *)URL
-(void)removeEntry:(WebHistoryItem *)entry
{
WebHistoryItem *removedEntry;
WebHistoryListNode *node;
unsigned hash;
removedEntry = nil;
hash = [URL hash];
WebHistoryItem *removedEntry = nil;
NSURL *URL = [entry URL];
unsigned hash = [URL hash];
WebHistoryListNode *node;
for (node = _head; node != nil; node = node->next) {
if (hash == node->hash && [URL isEqual:[node->entry URL]]) {
_count--;
......@@ -199,56 +158,14 @@ -(WebHistoryItem *)removeURL:(NSURL *)URL
break;
}
}
return removedEntry;
}
-(BOOL)removeEntry:(WebHistoryItem *)entry
{
BOOL removed;
WebHistoryListNode *node;
unsigned hash;
removed = NO;
hash = [entry hash];
for (node = _head; node != nil; node = node->next) {
if (hash == node->hash && [entry isEqual:node->entry]) {
_count--;
removed = YES;
if (node == _head) {
_head = node->next;
if (_head) {
_head->prev = nil;
}
}
else if (node == _tail) {
_tail = node->prev;
if (_tail) {
_tail->next = nil;
}
}
else {
node->prev->next = node->next;
node->next->prev = node->prev;
}
freeNode(node);
break;
}
}
return removed;
}
-(WebHistoryItem *)entryForURL:(NSURL *)URL
{
WebHistoryItem *foundEntry;
WebHistoryListNode *node;
unsigned hash;
foundEntry = nil;
hash = [URL hash];
WebHistoryItem *foundEntry = nil;
unsigned hash = [URL hash];
WebHistoryListNode *node;
for (node = _head; node != nil; node = node->next) {
if (hash == node->hash && [URL isEqual:[node->entry URL]]) {
foundEntry = node->entry;
......@@ -261,13 +178,10 @@ -(WebHistoryItem *)entryForURL:(NSURL *)URL
-(WebHistoryItem *)entryAtIndex:(int)index
{
int i;
WebHistoryListNode *node;
WEBKIT_ASSERT(index >= 0 && index < _count);
node = _head;
WebHistoryListNode *node = _head;
int i;
for (i = 0; i < index; i++) {
node = node->next;
}
......@@ -275,22 +189,32 @@ -(WebHistoryItem *)entryAtIndex:(int)index
return node->entry;
}
-(WebHistoryItem *)removeEntryAtIndex:(int)index
-(void)replaceEntryAtIndex:(int)index withEntry:(WebHistoryItem *)entry
{
WebHistoryItem *removedEntry;
WebHistoryListNode *node;
WEBKIT_ASSERT(index >= 0 && index < _count);
WebHistoryListNode *node = _head;
int i;
for (i = 0; i < index; i++) {
node = node->next;
}
WEBKIT_ASSERT(index > 0 && index < _count);
[node->entry autorelease];
node->entry = [entry retain];
}
node = _head;
-(WebHistoryItem *)removeEntryAtIndex:(int)index
{
WEBKIT_ASSERT(index > 0 && index < _count);
WebHistoryListNode *node = _head;
int i;
for (i = 0; i < index; i++) {
node = node->next;
}
_count--;
removedEntry = node->entry;
WebHistoryItem *removedEntry = node->entry;
if (node == _head) {
_head = node->next;
if (_head) {
......@@ -314,19 +238,15 @@ -(WebHistoryItem *)removeEntryAtIndex:(int)index
-(void)removeEntriesToIndex:(int)index
{
WebHistoryListNode *node;
WebHistoryListNode *delNode;
int i;
WEBKIT_ASSERT(index > 0 && index < _count);
node = _head;
WebHistoryListNode *node = _head;
int i;
for (i = 0; i < index; i++) {
delNode = node;
node = node->next;
freeNode(delNode);
WebHistoryListNode *next = node->next;
freeNode(node);
_count--;
node = next;
}
_head = node;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment