From 0ba61f1714b85eaeb6ba12742872d361d1cbab84 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 31 Dec 2009 09:18:37 +0100 Subject: [PATCH] Record news more compactly Member nws_uid is unused since the commit before previous. Remove it. Member nws_seqno is of marginal value, because we write news only through ncache[], and thus aren't prone to the errors sequence numbers can catch. Remove it. Make timestamp selector virtual, computing nws_when + nws_duration, and remove member nws_timestamp. Impact: * In ncache(), the removed timestamp equals nws_when + nws_duration, both for new news and updated news. No change. * delete_old_news() becomes invisible. Before, its move of unexpired news to the beginning of the news file touched all the timestamps. That was unwanted, because the move does not change news, only their storage. Improvement. * empdump no longer flags the imported news changed via the timestamp. This is somewhat unfortunate. Document as bug. With these members removed, struct nwsstr no longer matches struct emptypedstr, so clear news table flag EFF_TYPED and remove union empobj_storage member news. This loses the automatic maintenance of member ef_type via struct emptypedstr. Remove ef_type as well. This shrinks struct nwsstr from 20 to 12 bytes on common 32 bit machines, and from 32 to 16 bytes on common 64 bit machines. Since the server doesn't map the whole news file (EFF_MAP is off), this reduces I/O, while the table's memory use remains the same. Historical note: struct nwsstr is now pretty much what it was back in BSD Empire 1.1. Members ef_type and nws_uid go back to Empire 3 (for C_SYNC?). v4.3.12 added member nws_timestamp, which doubled the size on common 64 bit machines. v4.3.15 added nws_seqno. --- include/empobj.h | 1 - include/news.h | 6 ------ info/xdump.t | 2 ++ src/lib/common/filetable.c | 2 +- src/lib/common/nsc.c | 14 +++++++++++--- src/lib/subs/nreport.c | 1 - 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/empobj.h b/include/empobj.h index 713f2f4a5..373ec0212 100644 --- a/include/empobj.h +++ b/include/empobj.h @@ -84,7 +84,6 @@ union empobj_storage { struct lonstr loan; struct loststr lost; struct natstr nat; - struct nwsstr news; struct nukstr nuke; struct plnstr plane; struct realmstr realm; diff --git a/include/news.h b/include/news.h index 54d7ef9f0..b6853a99e 100644 --- a/include/news.h +++ b/include/news.h @@ -45,12 +45,6 @@ #include "nsc.h" struct nwsstr { - /* initial part must match struct empobj */ - short ef_type; - short nws_uid; - unsigned nws_seqno; - time_t nws_timestamp; - /* end of part matching struct empobj */ natid nws_ano; /* "actor" country # */ unsigned char nws_vrb; /* action (verb) */ natid nws_vno; /* "victim" country # */ diff --git a/info/xdump.t b/info/xdump.t index 95ab16008..4521c7122 100644 --- a/info/xdump.t +++ b/info/xdump.t @@ -97,6 +97,8 @@ yet available in human-readable form: the lost file, sect-chr selector nav, ship and land plague status (deity only), plane theta (governs satellite movement), trade selectors xloc, yloc, commodity selectors xbuy, ybuy. +Incremental dump doesn't work after importing news with the empdump +utility. .s1 .L "FUTURE DIRECTIONS:" xdump is still fairly new, and experience with it may lead to changes. diff --git a/src/lib/common/filetable.c b/src/lib/common/filetable.c index 100c3f470..8bfb1bbfd 100644 --- a/src/lib/common/filetable.c +++ b/src/lib/common/filetable.c @@ -133,7 +133,7 @@ struct empfile empfile[] = { {EF_NUKE, "nuke", "nuke", nuke_ca, UNMAPPED_CACHE(struct nukstr, EFF_TYPED | EFF_XY | EFF_OWNER)}, {EF_NEWS, "news", "news", news_ca, - UNMAPPED_CACHE(struct nwsstr, EFF_TYPED)}, + UNMAPPED_CACHE(struct nwsstr, 0)}, {EF_TREATY, "treaty", "treaty", treaty_ca, UNMAPPED_CACHE(struct trtstr, EFF_TYPED)}, {EF_TRADE, "trade", "trade", trade_ca, diff --git a/src/lib/common/nsc.c b/src/lib/common/nsc.c index eb0348ee9..c237b5e0f 100644 --- a/src/lib/common/nsc.c +++ b/src/lib/common/nsc.c @@ -67,6 +67,7 @@ static void *nsc_lnd_acc(struct valstr *, struct natstr *, void *); static void *nsc_lnd_dam(struct valstr *, struct natstr *, void *); static void *nsc_lnd_aaf(struct valstr *, struct natstr *, void *); static void *nsc_lchr(struct valstr *, struct natstr *, void *); +static void *nsc_nws_timestamp(struct valstr *, struct natstr *, void *); /* Ugly hack to improve legibility by avoid long lines */ #define fldoff(fld) offsetof(CURSTR, fld) @@ -468,9 +469,7 @@ struct castr loan_ca[] = { struct castr news_ca[] = { #define CURSTR struct nwsstr - /* no need for uid as long as it's not referenced from other tables */ - {"timestamp", fldoff(nws_timestamp), NSC_TIME, 0, NULL, - EF_BAD, NSC_EXTRA}, + {"timestamp", 0, NSC_LONG, 0, nsc_nws_timestamp, EF_BAD, NSC_EXTRA}, {"actor", fldoff(nws_ano), NSC_NATID, 0, NULL, EF_NATION, 0}, {"action", fldoff(nws_vrb), NSC_UCHAR, 0, NULL, EF_NEWS_CHR, 0}, {"victim", fldoff(nws_vno), NSC_NATID, 0, NULL, EF_NATION, 0}, @@ -915,3 +914,12 @@ nsc_lchr(struct valstr *val, struct natstr *np, void *ptr) val->val_as.sym.get = NULL; return lchr + ((struct lndstr *)ptr)->lnd_type; } + +static void * +nsc_nws_timestamp(struct valstr *val, struct natstr *natp, void *ptr) +{ + struct nwsstr *np = ptr; + + val->val_as.lng = np->nws_when + np->nws_duration; + return NULL; +} diff --git a/src/lib/subs/nreport.c b/src/lib/subs/nreport.c index 2d92aa8a1..cfb5641bd 100644 --- a/src/lib/subs/nreport.c +++ b/src/lib/subs/nreport.c @@ -117,7 +117,6 @@ delete_old_news(void) for (j = 0; getnews(i + j, &news); j++) { if (news.nws_vrb == 0) break; - ef_set_uid(EF_NEWS, &news, j); putnews(j, &news); } CANT_HAPPEN(i + j != news_tail); -- 2.43.0