Hi,

Now that trunk is open again, I have committed the patch I posted one
month ago (patch #1126). Note that this work is not yet complete.

This patch removes all the implementation details that leak from the
config class. That way, once the rest of Wesnoth is no longer impacted
by the implementation of config, we will be able to focus on greatly
reducing the memory footprint (some early tests on a pseudo-Wesnoth
show -85% memory for WML objects) and improving the engine speed.

So, what are the changes for C++ developers?

** The config::values field no longer exists. If you need to iterate
over all the attributes of a config object, the idiom is

foreach (const config::attribute &attr, cfg.attribute_range()) {
  assert(cfg[attr.first] == attr.second);
}

** The config::get_children method no longer exists (in fact, it still
does, but that's just because it's work in progress). The idiom is now

foreach ([const] config &child, cfg.child_range("key"))

As a side note, I have noticed the functions config::child_count and
config::find_child are hardly used in Wesnoth. Think about them before
writing your next loop.

If you are one of the developers that have been abusing
config::get_children in order to physically modify constant config
objects, 1. shame on you, 2. think a bit more about the specification
of your algorithms before coding. If you find some const_cast's while
browsing the code, it's my not having a clue how to fix the old code,
so I have used a cast to get back to the old behavior.

** As you can guess, the next offender on my kill list is
config::all_children. If you are about to use it, please wonder if
config::ordered_... wouldn't do the same job just fine. This will
reduce the amount of changes later when I get to it.

Best regards,

Guillaume

_______________________________________________
Wesnoth-dev mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-dev

Reply via email to