2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

ofpbuf: New function ofpbuf_const_initializer().

A number of times I've looked at code and thought that it would be easier
to understand if I could write an initializer instead of
ofpbuf_use_const().  This commit adds a function for that purpose and
adapts a lot of code to use it, in the places where I thought it made
the code better.

In theory this could improve code generation since the new function can
be inlined whereas ofpbuf_use_const() isn't.  But I guess that's probably
insignificant; the intent of this change is code readability.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
This commit is contained in:
Ben Pfaff
2016-02-18 15:13:09 -08:00
parent de658847fd
commit 0a2869d524
14 changed files with 250 additions and 425 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1801,15 +1801,12 @@ static void
log_nlmsg(const char *function, int error,
const void *message, size_t size, int protocol)
{
struct ofpbuf buffer;
char *nlmsg;
if (!VLOG_IS_DBG_ENABLED()) {
return;
}
ofpbuf_use_const(&buffer, message, size);
nlmsg = nlmsg_to_string(&buffer, protocol);
struct ofpbuf buffer = ofpbuf_const_initializer(message, size);
char *nlmsg = nlmsg_to_string(&buffer, protocol);
VLOG_DBG_RL(&rl, "%s (%s): %s", function, ovs_strerror(error), nlmsg);
free(nlmsg);
}