[ovs-dev] [PATCH 2/2] idl: New helpers for accessing string maps.

Ben Pfaff blp at nicira.com
Wed Mar 21 23:59:15 UTC 2012


On Wed, Mar 21, 2012 at 03:57:33PM -0700, Ethan Jackson wrote:
> This removes some boilerplate from the bridge.
> 
> Signed-off-by: Ethan Jackson <ethan at nicira.com>

If you define keys, values, and result_key as 'char **const', instead
of as 'const char **', then you can drop the casts:
> +    const char **keys = (const char **) row->key_%(c)s;
> +    const char **values = (const char **) row->value_%(c)s;
> +    size_t n_keys = row->n_%(c)s;
> +    const char **result_key;

You can rewrite *(values + (result_key - keys)) as values[result_key -
keys]:
> +    return result_key ? *(values + (result_key - keys)) : default_value;

I have a slight preference for writing () around the expression rather
than using \ here:
> +def is_string_map(column):
> +    return column.type.key \
> +            and column.type.value \
> +            and column.type.key.type == ovs.db.types.StringType \
> +            and column.type.value.type == ovs.db.types.StringType

(The Google Python style guide, which we refer to sometimes, agrees
with me.)



More information about the dev mailing list