Skip to content

Commit

Permalink
Inital attr-arrays checkin: Store attributes on objects in arrays, no…
Browse files Browse the repository at this point in the history
…t linked lists.
  • Loading branch information
shawnw committed Feb 2, 2018
1 parent f5e2e39 commit 1b22726
Show file tree
Hide file tree
Showing 15 changed files with 720 additions and 651 deletions.
3 changes: 2 additions & 1 deletion .clang-format
Expand Up @@ -8,7 +8,8 @@ AlwaysBreakAfterReturnType: AllDefinitions
BreakBeforeBraces: Linux
ColumnLimit: 80
ContinuationIndentWidth: 2
ForEachMacros: ['DESC_ITER_CONN', 'DESC_ITER' ]
ForEachMacros: ['DESC_ITER_CONN', 'DESC_ITER', 'DOLIST', 'DOLIST_VISIBLE',
'ATTR_FOR_EACH' ]
IndentCaseLabels: false
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: true
Expand Down
7 changes: 5 additions & 2 deletions CHANGES.187.md
Expand Up @@ -22,8 +22,11 @@ Version 1.8.7 patchlevel 0 ??? ?? 20??
Major Changes
-------------

* Support websocket connections. See <https://github.com/grapenut/websockclient> for a
sample in-browser client. [Grapenut, 1007]
* Support websocket connections. See
<https://github.com/grapenut/websockclient> for a sample in-browser
client. [Grapenut, 1007]
* Change attributes from being stored in sorted linked lists to sorted
arrays; results in faster lookups and less memory usage. [SW]

Softcode
--------
Expand Down
431 changes: 214 additions & 217 deletions hdrs/atr_tab.h

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions hdrs/attrib.h
Expand Up @@ -19,9 +19,8 @@
struct attr {
char const *name; /**< Name of attribute */
uint32_t flags; /**< Attribute flags */
chunk_reference_t data; /**< The attribute's value, compressed */
dbref creator; /**< The attribute's creator's dbref */
ATTR *next; /**< Pointer to next attribute in list */
chunk_reference_t data; /**< The attribute's value, compressed */
};

/** An alias for an attribute.
Expand All @@ -48,6 +47,9 @@ const char *check_attr_value(dbref player, const char *name, const char *value);
int cnf_attribute_access(char *attrname, char *opts);

void add_new_attr(char *name, uint32_t flags);
bool attr_reserve(dbref, int);
void attr_shrink(dbref);

/* From attrib.c */

/** atr_add(), atr_clr() error codes */
Expand Down Expand Up @@ -169,9 +171,12 @@ extern ATTR attr[]; /**< external predefined attributes. */
#define AL_STR(alist) (atr_get_compressed_data((alist)))
/** The raw length of the (possibly compressed) attribute text. */
#define AL_STRLEN(alist) ((alist)->data ? chunk_len((alist)->data) : 0)
#define AL_NEXT(alist) ((alist)->next)
#define AL_CREATOR(alist) ((alist)->creator)
#define AL_FLAGS(alist) ((alist)->flags)
#define AL_DEREFS(alist) ((alist)->data ? chunk_derefs((alist)->data) : 0)

#define ATTR_FOR_EACH(obj, var) \
if (List(obj)) \
for (var = List(obj); AL_NAME(var); var++)

#endif /* __ATTRIB_H */
5 changes: 4 additions & 1 deletion hdrs/dbdefs.h
Expand Up @@ -50,6 +50,7 @@ extern dbref first_free; /* pointer to free list */
#define ModTime(x) (db[(x)].modification_time)

#define AttrCount(x) (db[(x)].attrcount)
#define AttrCap(x) (db[(x)].attrcap)

/* Moved from warnings.c because create.c needs it. */
#define Warnings(x) (db[(x)].warnings)
Expand Down Expand Up @@ -189,6 +190,7 @@ extern dbref first_free; /* pointer to free list */
#define AF_Mhear(a) ((a)->flags & AF_MHEAR)
#define AF_Ahear(a) ((a)->flags & AF_AHEAR)
#define AF_Quiet(a) ((a)->flags & AF_QUIET)
#define AF_Root(a) ((a)->flags & AF_ROOT)

/* Non-mortal checks */
#define God(x) ((x) == GOD)
Expand Down Expand Up @@ -269,10 +271,11 @@ struct object {
*/
time_t modification_time;
int attrcount; /**< Number of attribs on the object */
int attrcap; /**< Size of the attribute array */
int type; /**< Object's type */
object_flag_type flags; /**< Pointer to flag bit array */
object_flag_type powers; /**< Pointer to power bit array */
ALIST *list; /**< list of attributes on the object */
ALIST *list; /**< Array of attributes on the object */
};

/** A structure to hold database statistics.
Expand Down
3 changes: 1 addition & 2 deletions src/atr_tab.c
Expand Up @@ -218,7 +218,6 @@ attr_read(PENNFILE *f)
a->data = NULL_CHUNK_REFERENCE;
AL_FLAGS(a) = 0;
AL_CREATOR(a) = GOD;
a->next = NULL;

db_read_this_labeled_string(f, "name", &tmp);

Expand Down Expand Up @@ -801,7 +800,7 @@ do_attribute_access(dbref player, char *name, char *perms, int retroactive)
if (retroactive) {
for (i = 0; i < db_top; i++) {
if ((ap2 = atr_get_noparent(i, name))) {
if (AL_FLAGS(ap2) & AF_ROOT)
if (AF_Root(ap2))
AL_FLAGS(ap2) = flags | AF_ROOT;
else
AL_FLAGS(ap2) = flags;
Expand Down

0 comments on commit 1b22726

Please sign in to comment.