On 2013/10/26 12:47, Cameron McCormack wrote:
Tim Abraldes:
So my question is this; is it preferable to keep the As*Event
functions, or to use regular C++ casts to accomplish the same
behavior? We could use static_cast unconditionally for upcasts,
static_cast with a check of |eventStructType| for downcasts to
most-derived event types, and dynamic_cast for downcasts to
non-most-derived event types.
Masayuki Nakano:
Please use As*Event() in case #1 and #2. As you said, we can use
static_cast since there is eventStructType. However, it's NOT safe
because we *might* take mistakes. Actually, there was such bug. If
somebody takes mistake, it may cause breaking memory if it sets
value to the member.
# Anyway, we don't need to do anything in case #3.
Additionally, the user code becomes simple since we can avoid
checking eventStructType member ;-)
Would it make sense to make eventStructType exist only in debug builds,
and to assert its value inside the As*Event() functions?
I have no idea why you thinks eventStructType should be only in debug build.
Unfortunately, eventStructType indicate only only leaf class type. There
are NS_SVGZOOM_EVENT and NS_SMIL_TIME_EVENT. These constants are used
for WidgetGUIEvent and InternalUIEvent. And when creating DOM event,
these values cause creating different DOM event class from NS_GUI_EVENT
and NS_UI_EVENT. I think that they should be removed and used message
values at creating the events, though.
If we can fix above issue, I guess that we can completely hide the
member. Then, if we chose to use virtual method for implementing
Is*Event(), we can remove it. But I think that it's better to use
eventStructType in them since they are called a lot of times. So,
non-virtual methods give better performance for us.
--
Masayuki Nakano <masay...@d-toybox.com>
Manager, Internationalization, Mozilla Japan.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform