Reference-counting in Befehlen. Derzeit nur für Befehle ohne Parameter.

jetzt mit define SHARE_ORDERS aktivierbar.
This commit is contained in:
Enno Rehling 2005-05-09 20:01:28 +00:00
parent c755cf39f2
commit e2d87d2b2a
1 changed files with 10 additions and 4 deletions

View File

@ -21,16 +21,19 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define SHORT_STRINGS
#define SHARE_ORDERS
typedef struct locale_data { typedef struct locale_data {
#ifdef SHARE_ORDERS
struct order_data * short_orders[MAXKEYWORDS]; struct order_data * short_orders[MAXKEYWORDS];
#endif
const struct locale * lang; const struct locale * lang;
} locale_data; } locale_data;
static struct locale_data * locale_array[16]; static struct locale_data * locale_array[16];
static int nlocales = 0; static int nlocales = 0;
#undef SHORT_STRINGS
typedef struct order_data { typedef struct order_data {
char * _str; char * _str;
keyword_t _keyword; keyword_t _keyword;
@ -178,15 +181,16 @@ parse_order(const char * s, const struct locale * lang)
ord = (order*)malloc(sizeof(order)); ord = (order*)malloc(sizeof(order));
ord->_persistent = persistent; ord->_persistent = persistent;
ord->next = NULL; ord->next = NULL;
ord->data = NULL;
#ifdef SHARE_ORDERS
if (kwd!=NOKEYWORD && *sptr == 0) { if (kwd!=NOKEYWORD && *sptr == 0) {
ord->data = locale_array[i]->short_orders[kwd]; ord->data = locale_array[i]->short_orders[kwd];
if (ord->data != NULL) { if (ord->data != NULL) {
++ord->data->_refcount; ++ord->data->_refcount;
} }
} else {
ord->data = NULL;
} }
#endif
if (ord->data==NULL) { if (ord->data==NULL) {
ord->data = (order_data*)malloc(sizeof(order_data)); ord->data = (order_data*)malloc(sizeof(order_data));
@ -194,10 +198,12 @@ parse_order(const char * s, const struct locale * lang)
ord->data->_str = NULL; ord->data->_str = NULL;
ord->data->_refcount = 1; ord->data->_refcount = 1;
ord->data->_keyword = kwd; ord->data->_keyword = kwd;
#ifdef SHARE_ORDERS
if (kwd!=NOKEYWORD && *sptr == 0) { if (kwd!=NOKEYWORD && *sptr == 0) {
locale_array[i]->short_orders[kwd] = ord->data; locale_array[i]->short_orders[kwd] = ord->data;
++ord->data->_refcount; ++ord->data->_refcount;
} }
#endif
#ifdef SHORT_STRINGS #ifdef SHORT_STRINGS
if (ord->data->_keyword==NOKEYWORD) { if (ord->data->_keyword==NOKEYWORD) {
ord->data->_str = strdup(s); ord->data->_str = strdup(s);