X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fcaseproto.h;h=1556efb5df1a947dacd1bc588c928f6fd70fbee5;hb=051724c1769c04a715f00f22f75c4a810f5bff11;hp=b85a9f32d9260f02d6339b8f0852caca8518722f;hpb=bd17d2af982332ee1791998361b1ac6731fe14fa;p=pspp diff --git a/src/data/caseproto.h b/src/data/caseproto.h index b85a9f32d9..1556efb5df 100644 --- a/src/data/caseproto.h +++ b/src/data/caseproto.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,8 +21,10 @@ #include #include #include -#include -#include + +#include "data/value.h" +#include "libpspp/cast.h" +#include "libpspp/compiler.h" /* Case prototype. @@ -62,11 +64,10 @@ struct caseproto { size_t ref_cnt; /* Reference count. */ - /* Tracking of long string widths. Lazily maintained: when - 'long_strings' is null and 'n_long_strings' is nonzero, - the former must be regenerated. */ - size_t *long_strings; /* Array of indexes of long string widths. */ - size_t n_long_strings; /* Number of long string widths. */ + /* Tracking of string widths. Lazily maintained: when 'strings' is null + and 'n_strings' is nonzero, the former must be regenerated. */ + size_t *strings; /* Array of indexes of string widths. */ + size_t n_strings; /* Number of string widths. */ /* Widths. */ size_t n_widths; /* Number of widths. */ @@ -78,8 +79,8 @@ struct pool; /* Creation and destruction. */ struct caseproto *caseproto_create (void) MALLOC_LIKE; -static inline struct caseproto *caseproto_ref (const struct caseproto *); -struct caseproto *caseproto_ref_pool (const struct caseproto *, struct pool *); +static inline struct caseproto *caseproto_ref (const struct caseproto *) WARN_UNUSED_RESULT; +struct caseproto *caseproto_ref_pool (const struct caseproto *, struct pool *) WARN_UNUSED_RESULT; static inline void caseproto_unref (struct caseproto *); /* Inspecting stored widths. */ @@ -116,14 +117,13 @@ void caseproto_destroy_values (const struct caseproto *, union value[]); void caseproto_copy (const struct caseproto *, size_t idx, size_t count, union value *dst, const union value *src); -/* Inspecting the cache of long string widths. +/* Inspecting the cache of string widths. - (These functions are useful for allocating cases, which - requires allocating a block memory for each long string value - in the case.) */ -static inline size_t caseproto_get_n_long_strings (const struct caseproto *); -static inline size_t caseproto_get_long_string_idx (const struct caseproto *, - size_t idx1); + (These functions are useful for allocating cases, which requires allocating + a block of memory for each string value in the case.) */ +static inline size_t caseproto_get_n_strings (const struct caseproto *); +static inline size_t caseproto_get_string_idx (const struct caseproto *, + size_t idx1); /* For use in assertions. */ bool caseproto_range_is_valid (const struct caseproto *, @@ -144,7 +144,7 @@ void caseproto_free__ (struct caseproto *); static inline struct caseproto * caseproto_ref (const struct caseproto *proto_) { - struct caseproto *proto = (struct caseproto *) proto_; + struct caseproto *proto = CONST_CAST (struct caseproto *, proto_); proto->ref_cnt++; return proto; } @@ -156,7 +156,7 @@ caseproto_ref (const struct caseproto *proto_) static inline void caseproto_unref (struct caseproto *proto) { - if (proto != NULL && !--proto->ref_cnt) + if (proto != NULL && --proto->ref_cnt == 0) caseproto_free__ (proto); } @@ -180,30 +180,27 @@ caseproto_get_n_widths (const struct caseproto *proto) /* Inspecting the cache of long string widths. */ -void caseproto_refresh_long_string_cache__ (const struct caseproto *); +void caseproto_refresh_string_cache__ (const struct caseproto *); -/* Returns the number of long string widths in PROTO; that is, - the number of widths in PROTO that are greater than to - MAX_SHORT_STRING. */ +/* Returns the number of strings in PROTO. */ static inline size_t -caseproto_get_n_long_strings (const struct caseproto *proto) +caseproto_get_n_strings (const struct caseproto *proto) { - return proto->n_long_strings; + return proto->n_strings; } -/* Given long string width IDX1, returns a value IDX2 for which - caseproto_get_width(PROTO, IDX2) will return a value greater - than MAX_SHORT_STRING. IDX1 must be less than - caseproto_get_n_long_strings(PROTO), and IDX2 will be less - than caseproto_get_n_widths(PROTO). */ +/* Given string width IDX1, returns a value IDX2 for which + caseproto_get_width(PROTO, IDX2) will return a value greater than 0. IDX1 + must be less than caseproto_get_n_strings(PROTO), and IDX2 will be less than + caseproto_get_n_widths(PROTO). */ static inline size_t -caseproto_get_long_string_idx (const struct caseproto *proto, size_t idx1) +caseproto_get_string_idx (const struct caseproto *proto, size_t idx1) { - if (proto->long_strings == NULL) - caseproto_refresh_long_string_cache__ (proto); + if (proto->strings == NULL) + caseproto_refresh_string_cache__ (proto); - assert (idx1 < proto->n_long_strings); - return proto->long_strings[idx1]; + assert (idx1 < proto->n_strings); + return proto->strings[idx1]; } #endif /* data/caseproto.h */