Andrew Stitcher <[EMAIL PROTECTED]> wrote:
> One more modest performance speed up (around 1.5%); unfortunately this
> is in code generated by the java generator so I don't really know where
> to start to fix this:
>
> In the generated file:
>
> BasicDeliverBody.h
>
> The constructor for BasicDeliverBody uses string by value where it
> should use it by constant reference,
>
> I'm not sure if there any other implications of this change, but it's
> worth doing here, and any other code just initialising string can do it
> through a const reference to avoid an unnecessary copy.
>
> [Incidentally I was surprised to see a bare "string" in a header file,
> the name space must be polluted somewhere]
>
> Andrew
>
> viz:
>> class BasicDeliverBody : virtual public AMQMethodBody
>> {
>> ...
>> BasicDeliverBody(ProtocolVersion version,
>> string consumerTag,
>> u_int64_t deliveryTag,
>> bool redelivered,
>> string exchange,
>> string routingKey
>> ) :
>> AMQMethodBody(version),
>> consumerTag(consumerTag),
>> deliveryTag(deliveryTag),
>> redelivered(redelivered),
>> exchange(exchange),
>> routingKey(routingKey)
>> { }
>> ...
>> }
>
> should be:
>
> class BasicDeliverBody : virtual public AMQMethodBody
> {
> ...
> BasicDeliverBody(ProtocolVersion version,
> const string& consumerTag,
> u_int64_t deliveryTag,
> bool redelivered,
> const string& exchange,
> const string& routingKey
> ) :
> AMQMethodBody(version),
> consumerTag(consumerTag),
> deliveryTag(deliveryTag),
> redelivered(redelivered),
> exchange(exchange),
> routingKey(routingKey)
> { }
> ...
> }
Hi Andrew,
When you suggested that, it rang a bell with me, since I'd looked into
removing some of the -Wshadow warnings, and those generated constructors
is a big source of the offenders. So I just happen to know how to do what
you want. Here's a patch that does it. There's probably a cleaner way to
do it, since I'm no java guru, and spent only an hour or so working on the
-Wshadow business, but this "works for me". FWIW, this induces changes
in most of the gen/*Body classes, not just the one you mentioned.
2006-12-15 Jim Meyering <[EMAIL PROTECTED]>
* src/org/apache/qpid/gentools/CppGenerator.java: Use a type
of "const string&", rather than "string", in all automatically
generated constructors. Suggested by Andrew Stitcher
Index: src/org/apache/qpid/gentools/CppGenerator.java
===================================================================
--- src/org/apache/qpid/gentools/CppGenerator.java (revision 487512)
+++ src/org/apache/qpid/gentools/CppGenerator.java (working copy)
@@ -1490,7 +1490,12 @@
{
int ordinal = oItr.next();
String[] fieldDomainPair = ordinalFieldMap.get(ordinal);
- sb.append(indent + (defineFlag ?
fieldDomainPair[FIELD_DOMAIN] + " " : "") +
+ String type_str = fieldDomainPair[FIELD_DOMAIN];
+ if (type_str.compareTo("string") == 0)
+ {
+ type_str = "const " + type_str + "&";
+ }
+ sb.append(indent + (defineFlag ? type_str + " " : "") +
fieldDomainPair[FIELD_NAME] + (initializerFlag
? "(" + fieldDomainPair[FIELD_NAME] + ")" : "") +
(oItr.hasNext() ? "," : "") + cr);
}
Here's the list of changed files.
The result does compile.
gen/AccessRequestBody.h | 2 +-
gen/BasicCancelBody.h | 2 +-
gen/BasicCancelOkBody.h | 2 +-
gen/BasicConsumeBody.h | 4 ++--
gen/BasicConsumeOkBody.h | 2 +-
gen/BasicDeliverBody.h | 6 +++---
gen/BasicGetBody.h | 2 +-
gen/BasicGetEmptyBody.h | 2 +-
gen/BasicGetOkBody.h | 4 ++--
gen/BasicPublishBody.h | 4 ++--
gen/BasicReturnBody.h | 6 +++---
gen/ChannelAlertBody.h | 2 +-
gen/ChannelCloseBody.h | 2 +-
gen/ChannelOpenBody.h | 2 +-
gen/ConnectionCloseBody.h | 2 +-
gen/ConnectionOpenBody.h | 4 ++--
gen/ConnectionOpenOkBody.h | 2 +-
gen/ConnectionRedirectBody.h | 4 ++--
gen/ConnectionSecureBody.h | 2 +-
gen/ConnectionSecureOkBody.h | 2 +-
gen/ConnectionStartBody.h | 4 ++--
gen/ConnectionStartOkBody.h | 6 +++---
gen/DtxStartBody.h | 2 +-
gen/ExchangeDeclareBody.h | 4 ++--
gen/ExchangeDeleteBody.h | 2 +-
gen/FileCancelBody.h | 2 +-
gen/FileCancelOkBody.h | 2 +-
gen/FileConsumeBody.h | 4 ++--
gen/FileConsumeOkBody.h | 2 +-
gen/FileDeliverBody.h | 8 ++++----
gen/FileOpenBody.h | 2 +-
gen/FilePublishBody.h | 6 +++---
gen/FileReturnBody.h | 6 +++---
gen/QueueBindBody.h | 6 +++---
gen/QueueDeclareBody.h | 2 +-
gen/QueueDeclareOkBody.h | 2 +-
gen/QueueDeleteBody.h | 2 +-
gen/QueuePurgeBody.h | 2 +-
gen/StreamCancelBody.h | 2 +-
gen/StreamCancelOkBody.h | 2 +-
gen/StreamConsumeBody.h | 4 ++--
gen/StreamConsumeOkBody.h | 2 +-
gen/StreamDeliverBody.h | 6 +++---
gen/StreamPublishBody.h | 4 ++--
gen/StreamReturnBody.h | 6 +++---
gen/TestStringBody.h | 4 ++--
gen/TestStringOkBody.h | 2 +-
gen/TestTableOkBody.h | 2 +-
48 files changed, 78 insertions(+), 78 deletions(-)