From 30cbec28c6dbd04064e786415df4f82eadcb8613 Mon Sep 17 00:00:00 2001 From: steffen Date: Sun, 21 Jul 2013 00:37:33 +0000 Subject: [PATCH] speeding up converting process. --- ChangeLog | 3 ++ base/memoryleak.h | 2 +- base/vector.c | 4 +-- mapsys/map.c | 2 -- mapsys/map.h | 2 +- mapsys/map_hash.c | 76 ++++++++++++++++++++------------------------ mapsys/map_osmload.c | 6 ++-- 7 files changed, 45 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c1eab4..b215703 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ Version 0.0.2: name changed to spOSMroute, since on there had been another OSMroute already. ============================================================================= +(2013-07-19): +- speeding up converting process. + (2013-06-17): - fixed: softkeyboard is working now with utf8. diff --git a/base/memoryleak.h b/base/memoryleak.h index 0c27f82..25e20b8 100644 --- a/base/memoryleak.h +++ b/base/memoryleak.h @@ -22,7 +22,7 @@ #if !defined(__MINGW32CE__) && !defined(_WIN32_WCE) #define ML_BT_SIZE 8 #define ML_BT_TEXT 100 - #define MEMORYLEAK_MAX 20000 + #define MEMORYLEAK_MAX 50000 #define MEMORYLEAK_MAXMEM 1500000000 #else #define ML_BT_SIZE 2 diff --git a/base/vector.c b/base/vector.c index a59c1bc..cb1143c 100644 --- a/base/vector.c +++ b/base/vector.c @@ -25,7 +25,7 @@ #include "osmroute.h" #include "vector.h" -fPoint vec_add (fPoint veca, fPoint vecb) { +inline fPoint vec_add (fPoint veca, fPoint vecb) { fPoint r; r.x = veca.x + vecb.x; @@ -35,7 +35,7 @@ fPoint vec_add (fPoint veca, fPoint vecb) { }; -fPoint vec_sub (fPoint veca, fPoint vecb) { +inline fPoint vec_sub (fPoint veca, fPoint vecb) { fPoint r; r.x = veca.x - vecb.x; diff --git a/mapsys/map.c b/mapsys/map.c index 77c3b02..fa99523 100644 --- a/mapsys/map.c +++ b/mapsys/map.c @@ -30,7 +30,6 @@ struct map_hash **mhash = NULL; int mhash_max = 0; -int mhash_pos = 0; struct map_lsstat *mlsstat = NULL; int map_busy = 0; extern int map_search_fd; @@ -83,7 +82,6 @@ void map_init () { mhash_max = MAP_HASH_MAX; mhash = (struct map_hash**) ml_malloc (sizeof (void*) * (mhash_max)); - mhash_pos = mhash_max/2; for (i = 0; i < mhash_max; i++) mhash[i] = NULL; }; diff --git a/mapsys/map.h b/mapsys/map.h index 5a15783..7fef18e 100644 --- a/mapsys/map.h +++ b/mapsys/map.h @@ -53,7 +53,7 @@ #define MAP_SEARCHLINE_LEN 128 -#define MAP_HASH_DEFAULTSIZE 4096 +#define MAP_HASH_DEFAULTSIZE 0x20000 #if defined(__MINGW32CE__) || defined(_WIN32_WCE) #define MAP_HASH_MAX 128 diff --git a/mapsys/map_hash.c b/mapsys/map_hash.c index 8232dc9..3c69774 100644 --- a/mapsys/map_hash.c +++ b/mapsys/map_hash.c @@ -73,37 +73,26 @@ struct map_hash *map_hash_geti (int ilon, int ilat, int loadflags) { struct map_hash *res = NULL; int hi; - hi = mhash_pos; - if (mhash[hi] && mhash[hi]->pos.ilon == ilon && mhash[hi]->pos.ilat == ilat) res = mhash[hi]; - else { - hi = mhash_pos+1; - if (hi >= mhash_max) hi = 0; - while (hi != mhash_pos) { - if (mhash[hi] && mhash[hi]->pos.ilon == ilon && mhash[hi]->pos.ilat == ilat) { - res = mhash[hi]; - break; - } + for (hi = 0; hi < mhash_max; hi++) + if (mhash[hi] && mhash[hi]->pos.ilon == ilon && mhash[hi]->pos.ilat == ilat) { + res = mhash[hi]; + for (; hi > 0; hi--) mhash[hi] = mhash[hi-1]; + mhash[0] = res; + return res; + } - if (++hi >= mhash_max) hi = 0; + if (loadflags & MHLOAD_RELOAD) { + if (mhash[mhash_max-1]) { + map_hash_free (mhash[mhash_max-1], 1); + mhash[mhash_max-1] = NULL; } - - if (res == NULL && loadflags & MHLOAD_RELOAD) { - res = map_load_hash (ilon, ilat); - if (res) { - if ((--mhash_pos) < 0) mhash_pos = mhash_max-1; - - /* add on the givin place, delete old entry */ - if (mhash[mhash_pos]) { - map_hash_free (mhash[mhash_pos], 1); - mhash[mhash_pos] = NULL; - } - - /* add or update */ - if (mhash[mhash_pos] != NULL) d_printf ("%s:%d map_hash_add: memory leak: not free spot", __FILE__, __LINE__); - mhash[mhash_pos] = res; + memmove (&mhash[1], &mhash[0], sizeof (struct map_hash*)*mhash_max-1); + mhash[0] = NULL; - DELFLAG (res->status, MS_changed); - } + res = map_load_hash (ilon, ilat); + if (res) { + mhash[0] = res; + DELFLAG (res->status, MS_changed); } } @@ -116,18 +105,22 @@ struct map_hash *map_hash_geti (int ilon, int ilat, int loadflags) { * if it already excist exchange it and free the old hash data from the memory */ int map_hash_add (struct map_hash *mh) { - int i; + int i, fi = -1; /* fi: free hash position */ struct map_hash *mhold = NULL; if (mh == NULL) return 0; /* check if we need to "UPDATE" or to add the hash data */ - for (mhold = NULL, i = 0; i < mhash_max; i++) if (mhash[i]) { + for (mhold = NULL, i = 0; i < mhash_max; i++) { + if (mhash[i]) { if (mhash[i]->pos.ilon == mh->pos.ilon && mhash[i]->pos.ilat == mh->pos.ilat) { mhold = mhash[i]; + fi = i; break; } } + else if (fi == -1) fi = i; + } if (mhold != NULL) { /* update !! NOSAVEING !! */ mhash[i] = NULL; @@ -135,19 +128,19 @@ int map_hash_add (struct map_hash *mh) { mhold = NULL; } - if ((--mhash_pos) < 0) mhash_pos = mhash_max-1; - /* add on the givin place, delete old entry */ - mhold = NULL; - if (mhash[mhash_pos]) { - map_hash_free (mhash[mhash_pos], 1); - mhash[mhash_pos] = NULL; + if (fi == -1) { + if (mhash[mhash_max-1]) { + map_hash_free (mhash[mhash_max-1], 1); + mhash[mhash_max-1] = NULL; + } + memmove (&mhash[0], &mhash[1], sizeof (struct map_hash*)*mhash_max-1); + mhash[0] = NULL; + mhash[0] = mh; } + else + mhash[fi] = mh; - /* add or update */ - if (mhash[mhash_pos] != NULL) d_printf ("%s:%d map_hash_add: memory leak: not free spot", __FILE__, __LINE__); - mhash[mhash_pos] = mh; - return 1; }; @@ -177,7 +170,8 @@ struct map_hash *map_hash_realloc (struct map_hash *mhorg, int memsize) { struct map_hash *res; int i = memsize; - if (i < mhorg->datasize) i = mhorg->datasize; + if (i < mhorg->datasize) return res; + res = map_hash_alloc (i); map_hash_copy (res, mhorg); diff --git a/mapsys/map_osmload.c b/mapsys/map_osmload.c index 268fcef..bfd81f6 100644 --- a/mapsys/map_osmload.c +++ b/mapsys/map_osmload.c @@ -415,7 +415,7 @@ struct s_osm_hashnodes *osm_hashnodes_load (short int hid, int loadhash) { /* - * all data will be saved imedatly so we need only to close the file + * all data will be saved immediately so we need only to close the file */ void osm_hashnodes_free (struct s_osm_hashnodes *hnode) { if (hnode->hid == -1) return; @@ -1378,7 +1378,7 @@ int osm_area_split_add (struct s_osmmarea *marea) { /******************************************************************** * save detail information of the node. This will also create the - * search table. + * search index. */ void osm_nodedetail_save (struct osm_nodedetail *onoded, struct osm_node *node) { int i, j; @@ -1665,7 +1665,7 @@ void osm_processdata (xmlTextReaderPtr reader) { return; } - onoded.id = onoded.id; + onoded.id = onode.id; osm_nodedetail_append (&onoded, (char*)k, (char*)v); free ((void *)k); free ((void *)v);