Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add string and pkgpair memlists to pw_hashdb

When we create the pw_hashdb during --crawl, a data store is required for the
duplicated strings and pkgpair. These should be manipulated by the relevant
functions instead of being exposed. The hashdb is an appropriate place for this.

Signed-off-by: Pang Yan Han <pangyanhan@gmail.com>
  • Loading branch information...
commit 2ac679caffa813d9702265404bdb04977f81e4df 1 parent f60d87d
Pang Yan Han authored

Showing 3 changed files with 24 additions and 14 deletions. Show diff stats Hide diff stats

  1. +5 1 memlist.c
  2. +5 0 memlist.h
  3. +14 13 query.c
6 memlist.c
@@ -8,9 +8,13 @@ struct memlist *memlist_new(unsigned int max_elems, unsigned int elemSz, int fre
8 8 struct memlist *memlist = xcalloc(1, sizeof(struct memlist));
9 9 memlist->max_elems = max_elems;
10 10 memlist->elemSz = elemSz;
11   - memlist->free_inner = free_inner;
12 11 memlist->pool = xcalloc(1, sizeof(struct memlist_node));
13 12 memlist->pool->data = xcalloc(max_elems, elemSz);
  13 +
  14 + if (free_inner != MEMLIST_NORM && free_inner != MEMLIST_PTR) {
  15 + free_inner = MEMLIST_NORM;
  16 + }
  17 + memlist->free_inner = free_inner;
14 18 return memlist;
15 19 }
16 20
5 memlist.h
@@ -15,6 +15,11 @@ struct memlist {
15 15 int free_inner;
16 16 };
17 17
  18 +enum {
  19 + MEMLIST_NORM = 0,
  20 + MEMLIST_PTR
  21 +};
  22 +
18 23 struct memlist *memlist_new(unsigned int max_elems, unsigned int elemSz, int free_inner);
19 24 /* Returns the final location of data in memlist after addition */
20 25 void *memlist_add(struct memlist *memlist, void *data);
27 query.c
@@ -196,6 +196,10 @@ struct pw_hashdb {
196 196
197 197 /* Cache provided->providing key-value mapping */
198 198 struct hashmap *provides_cache;
  199 +
  200 + /* Backing store for strings and pkgpair */
  201 + struct memlist *strpool;
  202 + struct memlist *pkgpool;
199 203 };
200 204
201 205 static struct pw_hashdb *hashdb_new(void)
@@ -212,6 +216,9 @@ static struct pw_hashdb *hashdb_new(void)
212 216
213 217 /* Cache provided->providing key-value mapping */
214 218 hashdb->provides_cache = hashmap_new((pw_hash_fn) sdbm, (pw_hashcmp_fn) strcmp);
  219 +
  220 + hashdb->strpool = memlist_new(4096, sizeof(char *), MEMLIST_PTR);
  221 + hashdb->pkgpool = memlist_new(4096, sizeof(struct pkgpair), MEMLIST_NORM);
215 222 return hashdb;
216 223 }
217 224
@@ -222,6 +229,8 @@ static void hashdb_free(struct pw_hashdb *hashdb)
222 229 hashbst_free(hashdb->local_provides);
223 230 hashbst_free(hashdb->sync_provides);
224 231 hashmap_free(hashdb->provides_cache);
  232 + memlist_free(hashdb->strpool);
  233 + memlist_free(hashdb->pkgpool);
225 234 free(hashdb);
226 235 }
227 236
@@ -462,12 +471,9 @@ void provides_walk(void *key, void *val)
462 471 * @param dbcache list of pmpkg_t * to be hashed
463 472 * @param htable hash table hashing struct pkgpair
464 473 * @param provides hashbst used to hash provides
465   - * @param strpool memlist of dynamically allocated strings
466   - * @param pkgpool memlist of struct pkgpair
467 474 */
468 475 static void hash_packages(alpm_list_t *dbcache, struct hash_table *htable,
469   - struct hashbst *provides, struct memlist *strpool,
470   - struct memlist *pkgpool)
  476 + struct hashbst *provides, struct pw_hashdb *hashdb)
471 477 {
472 478 alpm_list_t *i, *k;
473 479 pmpkg_t *pkg;
@@ -484,7 +490,7 @@ static void hash_packages(alpm_list_t *dbcache, struct hash_table *htable,
484 490
485 491 pkgpair.pkgname = pkgname;
486 492 pkgpair.pkg = pkg;
487   - memlist_ptr = memlist_add(pkgpool, &pkgpair);
  493 + memlist_ptr = memlist_add(hashdb->pkgpool, &pkgpair);
488 494 hash_insert(htable, memlist_ptr);
489 495
490 496 /* Provides */
@@ -495,7 +501,7 @@ static void hash_packages(alpm_list_t *dbcache, struct hash_table *htable,
495 501 }
496 502
497 503 dupstr = xstrdup(buf);
498   - memlist_ptr = memlist_add(strpool, &dupstr);
  504 + memlist_ptr = memlist_add(hashdb->strpool, &dupstr);
499 505 hashbst_insert(provides, memlist_ptr, (void *) pkgname);
500 506 }
501 507 }
@@ -513,9 +519,6 @@ int powaur_crawl(alpm_list_t *targets)
513 519 struct pkgpair pkgpair;
514 520 void *memlist_ptr;
515 521
516   - struct memlist *depstrs = memlist_new(4096, sizeof(char *), 1);
517   - struct memlist *pkgstore = memlist_new(4096, sizeof(struct pkgpair), 0);
518   -
519 522 struct pw_hashdb *hashdb = hashdb_new();
520 523
521 524 db = alpm_option_get_localdb();
@@ -524,13 +527,13 @@ int powaur_crawl(alpm_list_t *targets)
524 527 dbcache = alpm_db_get_pkgcache(db);
525 528 ASSERT(dbcache != NULL, return error(PW_ERR_LOCALDB_CACHE_NULL));
526 529
527   - hash_packages(dbcache, hashdb->local, hashdb->local_provides, depstrs, pkgstore);
  530 + hash_packages(dbcache, hashdb->local, hashdb->local_provides, hashdb);
528 531
529 532 syncdbs = alpm_option_get_syncdbs();
530 533 for (i = syncdbs; i; i = i->next) {
531 534 db = i->data;
532 535 hash_packages(alpm_db_get_pkgcache(db), hashdb->sync, hashdb->sync_provides,
533   - depstrs, pkgstore);
  536 + hashdb);
534 537 }
535 538
536 539 /* Do dependency crawling for target list */
@@ -538,8 +541,6 @@ int powaur_crawl(alpm_list_t *targets)
538 541 crawl_deps(hashdb, i->data);
539 542 }
540 543
541   - memlist_free(depstrs);
542   - memlist_free(pkgstore);
543 544 hashdb_free(hashdb);
544 545 return 0;
545 546 }

0 comments on commit 2ac679c

Please sign in to comment.
Something went wrong with that request. Please try again.