On 14.04.2013 21:31, Jonas Kulla wrote:
> 2013/4/14 Alexander Krivács Schrøder <alexsch...@gmail.com
> <mailto:alexsch...@gmail.com>>
>
>     Hi.
>
>     I'm trying to use Glib.TimeVal with its from_iso8601()
>     initializer, but
>     I can't get the generated C code not to contain a call to
>     g_get_current_time() first. At first, I tried this Vala code:
>
>     string iso8601_date = "1999-05-31T11:20:00";
>     TimeVal time_val;
>     time_val.from_iso8601(iso8601_date);
>
>     but that makes the compiler complain:
>
>     error: use of possibly unassigned local variable `time_val'
>
>     So then I tried this code:
>
>     string iso8601_date = "1999-05-31T11:20:00";
>     TimeVal time_val = TimeVal();
>     time_val.from_iso8601(iso8601_date);
>
>     but that makes the compiler output the following code:
>
>     g_get_current_time (&time_val);
>     g_time_val_from_iso8601 (iso8601_date, &time_val);
>
>     What do I do to make it not call g_get_current_time()? I know it's
>     probably minimal, but it's still wasted CPU cycles and extraneous code
>     to compile and whatnot, and I want the option to leave it out if
>     at all
>     possible. If it isn't possible, a way to make it possible should be
>     considered to be implemented.
>
>     Regards,
>     Alexander K. Schrøder
>
>
>     _______________________________________________
>     vala-list mailing list
>     vala-list@gnome.org <mailto:vala-list@gnome.org>
>     https://mail.gnome.org/mailman/listinfo/vala-list
>
>
> Hi,
>
> GTimeVal seems a little bit problematic. Ideally, you would want to
> declare
> the "from_iso8601" method as a named constructor to circumvent the default
> one (which results in the g_get_current_time), and from a small test I
> just did
> this works out fine Vala wise. The only problem I see is that this
> call returns
> a boolean indicating whether the conversion was successful, which would be
> lost without any way to find out the result. I guess the way it should
> really be
> done is to have the default constructor just initialize the struct to
> zero and have
> the "get_current_time" as a separate method, but for that additional
> glib code
> would have to exist.
>
> I think your best trade off would be to go with your first suggestion
> and ignore
> the valac warning. But why is circumventing the get_current_time call so
> important to you? Are you running this code in a tight loop?
>
> Jonas

I would go with my first suggestion, except it's an error and not a
warning, so it doesn't compile at all.

No, I don't particularly need to circumvent the call. This is mostly a
theoretical desire to be able to accomplish in Vala the same thing I
could accomplish in C.

Were I to write the code in C, I could just leave out the call, so why
shouldn't I be able to accomplish the same goal in Vala? Or, more
appropriately, why should Vala HAVE to call g_get_current_time just for
me to get a hold of a TimeVal struct?

For the most part, Vala produces code about as efficient as manual C
code can be written, which is one of the main reasons why I like Vala so
much, but when it decides to force me to throw in a function call that I
don't need, that feeling of efficiency falls a little short.

So yeah... mostly intellectual curiosity, really.

Regards,
Alexander K. Schrøder

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to