I'm facing a situation where using reflection could be useful, but I'm
wondering if this imposes a performance loss.
Would this (sightly modified extract from the C++ API[1]):
Foo foo = new Foo;
Descriptor* descriptor = foo->GetDescriptor();
FieldDescriptor* text_field = descriptor->FindFieldByName("text");
foo->ParseFromString(data);
Message::Reflection* reflection = foo->GetReflection();
std::cout << reflection->GetString(text_field);
be less efficient than this:
Foo foo;
foo.ParseFromString(data);
std::cout << foo.text();
?
Thank you.
[1] http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.message.html
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
TIGRE SE COMIO A EMPLEADO DE CIRCO: DETUVIERON A DUEÑO Y DOMADOR
-- Crónica TV
I'm sorry, I've posted the message using gmane NNTP interface but for some
reason it didn't arrived so I bounced it to the list and I forgot the To:
header is not set for newsgroups =)
> Yes, it's less efficient, since the regular (generated) accessor is an
> inline method, whereas the Reflection-based accessor is virtual. However,
> this only matters if you're using it in an inner loop in a
> performance-sensitive app.
Ok, so it's just a matter of function call only, there's no extra
processing or lookups when using the reflection API?
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
I am so psychosomatic it makes me sick just thinking about it!
-- George Constanza
Ok, so it's just a matter of function call only, there's no extra
processing or lookups when using the reflection API?