2013/4/14 Alexander Krivács Schrøder <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 > 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 _______________________________________________ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list