It's pretty strange that this makes a difference -- the Java compiler really
ought to drop redundant initializers automatically.  But yes, this has been
fixed in our internal branch.

Unfortunately the only release timeline is:  "When someone has time to do a
release."  It's a pretty involved process (a few weeks of solid effort).
 But I suspect we'll be doing one in the next month or two as we recently
added a new team member who needs to learn the process.

On Fri, Sep 10, 2010 at 2:47 PM, David Dabbs <dmda...@gmail.com> wrote:

>
> Thanks, Jason. Any timeline for when these internal patches will make it to
> protobuf 2.3.1?
>
> Thanks,
>
> David
>
>
> From: Jason Hsueh
> Sent: Friday, September 10, 2010 12:31 PM
> Subject: Re: [protobuf] Could Java initializers be elided for primitive
> fields in many cases?
>
> Indeed, this has actually been fixed internally but the changes have not
> been released yet.
>
> (Although, the code you referenced is the code to generate the
> clearFoo() method, which still must set things to the default)
>
>
> On Wed, Sep 8, 2010 at 1:05 PM, David Dabbs wrote:
>
> IIRC Java initializes these primitive types as
>
>   private boolean foo_boolean;    // false
>   private int     foo_int;        // 0
>   private long    foo_long;       // 0L
>   private float   foo_float;      // 0.0f
>   private double  foo_double;     // 0.0d
>
> But java_primitive_field.cc unconditionally emits initialization code even
> when the proto -derived default value from is the same as the organic
> default.
>
> Was there a performance reason for including the (seemingly) unnecessary
> init code?
> If not, would there be any harm is NOT explicitly initializing these
> primitive field(s)?
> Seems like not doing so would reduce code size.
>
>
>
> //
> // from java_primitive_field.cc
> //
>
>  JavaType type = GetJavaType(descriptor_);
>  if (type == JAVATYPE_STRING || type == JAVATYPE_BYTES) {
>    // The default value is not a simple literal so we want to avoid
> executing
>    // it multiple times.  Instead, get the default out of the default
> instance.
>    printer->Print(variables_,
>      "  result.$name$_ = getDefaultInstance().get$capitalized_name$();\n");
>  } else {
>    printer->Print(variables_,
>      "  result.$name$_ = $default$;\n");
>  }
>
>
> I didn't go as far as creating a patch in case there were specific reasons
> for the init code.
>
>
> Thanks,
>
> David
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to proto...@googlegroups.com.
> To unsubscribe from this group, send email to
> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to