Skip to content

Commit

Permalink
libutil/fname: make the API more cache table centric
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Apr 27, 2023
1 parent d286504 commit 5205c95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 13 additions & 4 deletions main/fname.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,31 @@ struct comp {

struct canonFnameCacheTable {
hashTable *table;
const char *cwd;
size_t cwd_len;
char *input_last;
char *return_last;
};

extern struct canonFnameCacheTable *canonFnameCacheTableNew (void)
extern struct canonFnameCacheTable *canonFnameCacheTableNew (const char *cwd)
{
struct canonFnameCacheTable *r = xMalloc (1, struct canonFnameCacheTable);
r->table = hashTableNew (7, hashCstrhash, hashCstreq,
eFree, eFree);
r->input_last = NULL;
r->return_last = NULL;

char *cwd_tmp = eStrdup (cwd);
r->cwd = canonicalizeAbsoluteFileName (cwd_tmp);
eFree (cwd_tmp);
r->cwd_len = strlen (r->cwd);

return r;
}

extern void canonFnameCacheTableDelete (struct canonFnameCacheTable *cache_table)
{
eFree ((void *)cache_table->cwd);
hashTableDelete (cache_table->table);
eFree (cache_table);
}
Expand Down Expand Up @@ -220,8 +229,8 @@ static char *canonicalizePathNew(const char *dir, size_t dir_len, const char *re
return r;
}

extern const char *canonicalizeRelativeFileName (const char *cwd, size_t cwd_len, const char *input,
struct canonFnameCacheTable *cache_table)
extern const char *canonicalizeRelativeFileName (struct canonFnameCacheTable *cache_table,
const char *input)
{
if (cache_table->input_last)
{
Expand All @@ -234,7 +243,7 @@ extern const char *canonicalizeRelativeFileName (const char *cwd, size_t cwd_len
if (r)
return r;

r = canonicalizePathNew (cwd, cwd_len, input);
r = canonicalizePathNew (cache_table->cwd, cache_table->cwd_len, input);

cache_table->input_last = eStrdup (input);
cache_table->return_last = r;
Expand Down
6 changes: 3 additions & 3 deletions main/fname.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#include "htable.h"

struct canonFnameCacheTable;
extern struct canonFnameCacheTable *canonFnameCacheTableNew (void);
extern struct canonFnameCacheTable *canonFnameCacheTableNew (const char *cwd);
extern void canonFnameCacheTableDelete (struct canonFnameCacheTable *cache_table);

/* Don't free the cstring returned from this function directly.
* This function stores the cstring to the cache.
*/
extern const char *canonicalizeRelativeFileName(const char *cwd, size_t cwd_len, const char *input,
struct canonFnameCacheTable *cache_table);
extern const char *canonicalizeRelativeFileName(struct canonFnameCacheTable *cache_table,
const char *input);

/*
* Resolve '.', '..', and '//' in FNAME as if the current working
Expand Down

0 comments on commit 5205c95

Please sign in to comment.