I left Swap() in the Message base interface, but addressed all other changes. If you ...
14 years, 10 months ago
(2009-06-16 04:11:41 UTC)
#3
I left Swap() in the Message base interface, but addressed all other changes.
If you want me to remove it from Message, I'm relatively indifferent. Anyway,
at long last here's the revised patch. Sorry it took a while, my wife got
pregnant, I moved to a house, my (real work) project got cancelled, ...
http://codereview.appspot.com/27053/diff/1/15
File src/google/protobuf/extension_set.cc (right):
http://codereview.appspot.com/27053/diff/1/15#newcode410
Line 410: extension->repeated_int32_value->RemoveLast(); break;
On 2009/03/16 23:22:12, kenton wrote:
> I'd prefer if the breaks were on their own lines.
Done.
http://codereview.appspot.com/27053/diff/1/15#newcode429
Line 429: default:
On 2009/03/16 23:22:12, kenton wrote:
> Please just omit the default case. That way, GCC will produce a compiler
> warning if one of the enums values is missing (and I compile with -Werror).
Done.
http://codereview.appspot.com/27053/diff/1/15#newcode459
Line 459: default:
On 2009/03/16 23:22:12, kenton wrote:
> Same here.
Done.
http://codereview.appspot.com/27053/diff/1/6
File src/google/protobuf/generated_message_reflection.cc (right):
http://codereview.appspot.com/27053/diff/1/6#newcode258
Line 258: {
On 2009/03/16 23:22:12, kenton wrote:
> Put the brace at the end of the previous line to match Google style.
Done.
http://codereview.appspot.com/27053/diff/1/6#newcode270
Line 270: //if (GetRaw<GenericRepeatedField>(message, field).GenericSize() > 0)
{
On 2009/03/16 23:22:12, kenton wrote:
> Remove commented code.
Done.
http://codereview.appspot.com/27053/diff/1/6#newcode273
Line 273: MutableRaw<GenericRepeatedField>(message1,
field)->GenericSwap(MutableRaw<GenericRepeatedField>(message2, field));
On 2009/03/16 23:22:12, kenton wrote:
> Please wrap code at 80 characters.
Done.
http://codereview.appspot.com/27053/diff/1/6#newcode278
Line 278: // TODO(ses): could be more efficient if it cleared field directly
rather than ClearField
On 2009/03/16 23:22:12, kenton wrote:
> Use either your name or your full e-mail address so that people know you
aren't
> @google.com.
Done.
http://codereview.appspot.com/27053/diff/1/6#newcode328
Line 328: /*
On 2009/03/16 23:22:12, kenton wrote:
> Why is all this commented out?
oops. cleared.
http://codereview.appspot.com/27053/diff/1/13
File src/google/protobuf/generated_message_reflection.h (right):
http://codereview.appspot.com/27053/diff/1/13#newcode143
Line 143: void Swap(Message* message, const FieldDescriptor* field, int index1,
int index2) const;
On 2009/03/16 23:22:12, kenton wrote:
> 80 chars
Done.
http://codereview.appspot.com/27053/diff/1/5
File src/google/protobuf/generated_message_reflection_unittest.cc (right):
http://codereview.appspot.com/27053/diff/1/5#newcode164
Line 164: EXPECT_EQ(size-j-1, reflection->FieldSize(message, field));
On 2009/03/16 23:22:12, kenton wrote:
> You should probably also check that the correct value was removed.
>
> Maybe instead of iterating through all the fields, you could instead just go
> through one field of each CppType, do RemoveLast() on it via the reflection
> interface, and then check the contents via the normal interface?
>
> It might even make sense to add methods to TestUtil::ReflectionTester like
> "RemoveLastRepeateds()" and "SwapRepeateds()", and methods to TestUtil like
> "ExpectLastRepeatedsRemoved()" and "ExpectLastRepeatedsSwapped()". Then you
can
> call those from here. This way you could follow the patterns in that file and
> you would not have to repeat as much work for regular fields vs. extensions.
I did as (I think) you suggested, but I don't know how much copy/pasting I
saved. A little, but I still needed an Expect* and an ExpectExtensions*.
http://codereview.appspot.com/27053/diff/1/5#newcode199
Line 199: for (int i=0; i<output.size(); ++i) {
On 2009/03/16 23:22:12, kenton wrote:
> Similarly here, I think you should target a field of each CppType by name
rather
> than iterate through them (possibly by adding code to test_util.cc). That way
> you can easily test that the results are correct. Currently it looks like you
> are only calling each method, not verifying results. (You are verifying that
a
> double-swap returns the message to its original state but this would pass even
> if Swap() did nothing.)
No, it tests the message both ways, after one swap and after two swaps
(returning to normalcy). See the TEST_SWAP_REPEATED_ELEMENTS(), testing against
the messageCopy. I rejiggered it anyway, to be less sneaky and more like the
rest of the tests...
http://codereview.appspot.com/27053/diff/1/5#newcode232
Line 232: reflection->Swap(&message, field, 0, 1);
On 2009/03/16 23:22:12, kenton wrote:
> This belongs in a separate test.
I left it in the same test but they're MUCH shorter now thanks to the TestUtil
move. Let me know if you want me to break it out anyway...
http://codereview.appspot.com/27053/diff/1/10
File src/google/protobuf/message.h (right):
http://codereview.appspot.com/27053/diff/1/10#newcode179
Line 179: // Swap the contents of the message with another message.
On 2009/03/16 23:22:12, kenton wrote:
> Please clarify that the other message must have the same Descriptor *and* be
of
> exactly the same class.
Done.
http://codereview.appspot.com/27053/diff/1/10#newcode491
Line 491: virtual void Swap(Message* message,
On 2009/03/16 23:22:12, kenton wrote:
> Let's call this SwapElements() instead. I don't like overloading methods with
> very different meanings.
Done.
http://codereview.appspot.com/27053/diff/1/10#newcode503
Line 503:
On 2009/03/16 23:22:12, kenton wrote:
> Remove this random newline that you added.
Done.
http://codereview.appspot.com/27053/diff/1/4
File src/google/protobuf/reflection_ops.cc (right):
http://codereview.appspot.com/27053/diff/1/4#newcode130
Line 130: /*
On 2009/03/16 23:22:12, kenton wrote:
> Please remove this code rather than commenting it out.
Done.
http://codereview.appspot.com/27053/diff/1/7
File src/google/protobuf/reflection_ops.h (right):
http://codereview.appspot.com/27053/diff/1/7#newcode61
Line 61: static void Swap(Message* message1, Message* message2);
On 2009/03/16 23:22:12, kenton wrote:
> I don't think there's any reason to add a Swap() method here when it's already
> an explicit method of the Message and Reflection interfaces. It doesn't
really
> add much.
I don't really understand - I thought I was just following the pattern laid down
by Clear(), IsInitialized(), etc. in this class. How is Swap different?
http://codereview.appspot.com/27053/diff/1/12
File src/google/protobuf/reflection_ops_unittest.cc (right):
http://codereview.appspot.com/27053/diff/1/12#newcode275
Line 275: TEST(ReflectionOpsTest, RemoveLastUnknown) {
On 2009/03/16 23:22:12, kenton wrote:
> The contents of this test appear to be the same as ClearUnknown. Remove it?
Done.
http://codereview.appspot.com/27053/diff/1/3
File src/google/protobuf/repeated_field.h (right):
http://codereview.appspot.com/27053/diff/1/3#newcode142
Line 142: void Swap(int index1, int index2);
On 2009/03/16 23:22:12, kenton wrote:
> Rename to SwapElements().
Done.
http://codereview.appspot.com/27053/diff/1/3#newcode415
Line 415: std::swap(*Mutable(index1), *Mutable(index2));
On 2009/03/16 23:22:12, kenton wrote:
> Don't use the std:: prefix here -- we want to use Koenig lookup for swap().
> Also, we use "using namespace std" anyway.
Done.
http://codereview.appspot.com/27053/diff/1/3#newcode473
Line 473: // TODO(ses): Can this be arranged somehow without the dynamic_cast?
On 2009/03/16 23:22:12, kenton wrote:
> You should use down_cast instead of dynamic_cast. (down_cast is defined in
> stubs/common.h. It is dynamic_cast with an assert in debug mode and
static_cast
> in opt mode.)
Done.
http://codereview.appspot.com/27053/diff/1/3#newcode664
Line 664: std::swap(*Mutable(index1), *Mutable(index2));
On 2009/03/16 23:22:12, kenton wrote:
> Just swap the pointers here, not the contents:
>
> swap(elements_[index1], elements_[index2]);
Done.
http://codereview.appspot.com/27053/diff/1/3#newcode668
Line 668: // for UnknownFieldSet in unknown_field_set.h.
On 2009/03/16 23:22:12, kenton wrote:
> (And then you don't need this specialization anymore.)
Done.
http://codereview.appspot.com/27053/diff/1/3#newcode674
Line 674: void RepeatedPtrField<Message>::Swap(int index1, int index2);
On 2009/03/16 23:22:12, kenton wrote:
> (Nor this one.)
Done.
http://codereview.appspot.com/27053/diff/1/3#newcode768
Line 768: // TODO(ses): Can this be arranged somehow without the dynamic_cast?
On 2009/03/16 23:22:12, kenton wrote:
> down_cast
Done.
Addressed suggestions from round 2, removing Message::Swap. Also moved unit tests to generated_message_reflection_unittest.cc. http://codereview.appspot.com/27053/diff/2002/3001 File ...
14 years, 10 months ago
(2009-06-25 04:37:43 UTC)
#5
I went ahead and make Reflection::Swap() a little faster by swapping has_bits directly, and then ...
14 years, 10 months ago
(2009-06-25 19:06:02 UTC)
#6
I went ahead and make Reflection::Swap() a little faster by swapping has_bits
directly, and then swapping the field values without looking at their has bits.
I also added you to CONTRIBUTORS.txt.
Committed as rev 155.
Thanks!
Issue 27053: patch to improve Swap and add RemoveLast
Created 15 years, 1 month ago by ses4j
Modified 14 years, 10 months ago
Reviewers: kenton
Base URL: http://protobuf.googlecode.com/svn/trunk/
Comments: 70