[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [Vala] private fields vs bodyless properties
- From: "Juerg Billeter" <j bitron ch>
- To: "Hans Vercammen" <hveso3 gmail com>
- Cc: vala-list <vala-list gnome org>
- Subject: Re: [Vala] private fields vs bodyless properties
- Date: Fri, 30 May 2008 10:40:44 +0200 (CEST)
Hi Hans,
On Fri, May 30, 2008 02:05, Hans Vercammen wrote:
> The strange thing is, that whenever "private int foo { get; set; }" is
> used as an rvalue it translates to something like self->priv->_foo, but
> when I use it as an lvalue the setter method gets invoked, which can
> cause overhead in some situations.
That's just a missing optimization. We will be able to replace the
function call by direct assignments in most cases in a future version.
> After some digging I found that I can also use _foo as property lvalue
> in the vala source bypassing the setter, but this feels more like a hack
> and im not sure if I can rely on that.
You should definitively not rely on that, it's a bug that Vala accepts
this at the moment. However, after adding the aforementioned optimization,
this won't be necessary anymore for performance reasons, either.
> Assigning private or protected values during construction is a rather
> common practice, but I don't know what the preferred solution would be.
> Personally I like the {get; set;} thing, even for just marking private
> fields read/write/construct only, but maybe some final optimization
> layer in the generator should simplify this.
I generally recommend the following for construct-only properties:
public string foo { private get; construct; }
For cases where this is a performance issue, we're improving the support
for non-GObject (but still GType-registered) classes, which follow more
closely the C# and Java construction scheme.
Juerg
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]