aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-10-29 22:52:03 +0200
committerSergey Poznyakoff <gray@gnu.org>2020-10-29 22:52:03 +0200
commit274985d77bf2e69dec8d7eb90bd3f752f115f6e9 (patch)
tree4c8b2d16d96d8d93719df2e8464dc2fccd8a048d
parent02bc2dc9bee96c0e7d93d23c6f0b7a24d0e17566 (diff)
downloadgdbm-274985d77bf2e69dec8d7eb90bd3f752f115f6e9.tar.gz
gdbm-274985d77bf2e69dec8d7eb90bd3f752f115f6e9.tar.bz2
Minor changes.
* src/bucket.c (_gdbm_cache_init): Minimum cache capacity is 1. * src/cachetree.c (_gdbm_cache_tree_lookup): Fix the description. (_gdbm_cache_tree_destroy): Speed up the tree traversal. * src/gdbmsetopt.c (setopt_gdbm_setcachesize): Don't enforce minimal cache capacity.
-rw-r--r--src/bucket.c7
-rw-r--r--src/cachetree.c31
-rw-r--r--src/gdbmsetopt.c2
3 files changed, 28 insertions, 12 deletions
diff --git a/src/bucket.c b/src/bucket.c
index 73a2d2f..979150a 100644
--- a/src/bucket.c
+++ b/src/bucket.c
@@ -547,11 +547,8 @@ _gdbm_write_bucket (GDBM_FILE dbf, cache_elem *ca_entry)
int
_gdbm_cache_init (GDBM_FILE dbf, size_t size)
{
- if (size < 3)
- {
- errno = EINVAL;
- return -1;
- }
+ if (size == 0)
+ size = 1;
if (size == dbf->cache_size)
return 0;
diff --git a/src/cachetree.c b/src/cachetree.c
index d552a2d..b0623a9 100644
--- a/src/cachetree.c
+++ b/src/cachetree.c
@@ -314,12 +314,11 @@ static void rbt_insert_fixup (cache_tree *tree, cache_node *n);
/* Look up the node with the given ADR.
If found, put it in *RETVAL and return node_found.
- Otherwise, if INSERT is TRUE, create a new node and insert it in the
- appropriate place in the tree. Store the address of the newly created
- node in *RETVAL and return node_new. If a new node cannot be created
- (memory exhausted), return node_failure.
+ Otherwise, create a new node and insert it at the appropriate place in
+ the tree. Store the address of the newly created node in *RETVAL and
+ return node_new.
- Otherwise, if INSERT is FALSE, store NULL in *RETVAL and return node_new.
+ If a new node cannot be created (memory exhausted), return node_failure.
*/
int
_gdbm_cache_tree_lookup (cache_tree *tree, off_t adr, cache_node **retval)
@@ -456,8 +455,28 @@ void
_gdbm_cache_tree_destroy (cache_tree *tree)
{
cache_node *n;
+
+ /* Free the allocated tree nodes. Traverse the tree as if it were
+ a simple binary tree: there's no use preserving RBT properties now.
+ */
while ((n = tree->root) != NULL)
- _gdbm_cache_tree_delete (tree, n);
+ {
+ if (!n->left)
+ tree->root = n->right;
+ else if (!n->right)
+ tree->root = n->left;
+ else
+ {
+ cache_node *p;
+ for (p = n->left; p->right; p = p->right)
+ ;
+ p->right = n->right;
+ tree->root = n->left;
+ }
+ free (n);
+ }
+
+ /* Free the avail list */
while ((n = tree->avail) != NULL)
{
tree->avail = n->parent;
diff --git a/src/gdbmsetopt.c b/src/gdbmsetopt.c
index e5a2067..d70f0f9 100644
--- a/src/gdbmsetopt.c
+++ b/src/gdbmsetopt.c
@@ -60,7 +60,7 @@ setopt_gdbm_setcachesize (GDBM_FILE dbf, void *optval, int optlen)
GDBM_SET_ERRNO (dbf, GDBM_OPT_ILLEGAL, FALSE);
return -1;
}
- return _gdbm_cache_init (dbf, (sz > 9) ? sz : 10);
+ return _gdbm_cache_init (dbf, sz);
}
static int

Return to:

Send suggestions and report system problems to the System administrator.