Comment 46 for bug 948788

Revision history for this message
In , Trevor Saunders (trev-saunders) wrote :

Comment on attachment 726580
Implement a replacement of atk_object_set_name() which mimics the behavior without calling atk_object_get_name()

>+static void
>+AtkObjectSetName(AtkObject *aAtkObj, const gchar *name)

so, both of the times this is called we have to check if we actually want to fire an event first. So why don't we refactor this stuff like this

make this function
static void
MaybeFireNameChange(AtkObject* aObj, nsString& aNewName)

then it can incapsilate the stuff about comparing against the old name.

>+ size_t name_len = strlen(name);
>+
>+ if (strlen(aAtkObj->name) >= name_len) {
>+ /* If the new name is shorter, then just use the old memory chunk
>+ * to minimize memory fragmentation. */
>+ memcpy(aAtkObj->name, name, name_len + 1);
>+ } else {
>+ g_free(aAtkObj->name);
>+ aAtkObj->name = g_strdup(name);

I'd be suprised if this isn't a win and possibly a loss. Especially since the best you can do is strlen while the allocator actually knows how big the block is.

otherwise this seems like the correct approach so f=me but I'd like to see another version before r+ :)