Re: [PATCH 10/37] xfs: pretty print metadata file types in error messages

Christoph Hellwig
2024-12-13T06:30:23Z

On Thu, Dec 12, 2024 at 05:03:11PM -0800, Darrick J. Wong wrote:
> +static inline const char *
> +xfs_metafile_type_str(enum xfs_metafile_type metatype)
> +{
> + static const struct {
> + enum xfs_metafile_type mtype;
> + const char *name;
> + } strings[] = { XFS_METAFILE_TYPE_STR };
> + unsigned int i;
> +
> + for (i = 0; i < ARRAY_SIZE(strings); i++) {
> + if (strings[i].mtype == metatype)
> + return strings[i].name;
> + }
> +
> + return NULL;
> +}

Having this as an inline helpers means not just the code, but also
the string array is duplicated in every caller. While there are only
two with your entire series that's still a lіttle suboptimal. Maybe
move it out of line to xfs_metafile.c?

And make the array file scope to be a little more readable.