~pitti/autopilot-gtk/unsupported-type-warning

« back to all changes in this revision

Viewing changes to lib/GtkNode.cpp

  • Committer: Martin Pitt
  • Date: 2013-11-26 12:35:30 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: martin.pitt@ubuntu.com-20131126123530-um0mogvp8aew1iwp
Avoid unnecessary temporary std::string 

In GtkNode::MatchStringProperty(), drop the temporary and unnecessary
std::string duplication of the property value; instead, compare the C string
directly. This avoids copying the string, and also seems to avoid a rare crash
when destroying the std::string at the end of the function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
284
284
  g_value_init(&dest_value, G_PARAM_SPEC_VALUE_TYPE(pspec));
285
285
  g_object_get_property(object_, name.c_str(), &dest_value);
286
286
  convert_value(pspec, &dest_value);
287
 
  std::string dest_string;
288
287
 
289
288
  if (G_VALUE_TYPE(&dest_value) == G_TYPE_STRING) {
290
289
      const gchar *str = g_value_get_string(&dest_value);
291
 
      dest_string = (str != NULL) ? str : "";
 
290
      int result = g_strcmp0 (str, value.c_str());
292
291
      g_value_unset(&dest_value);
293
 
      return dest_string == value;
 
292
      return result == 0;
294
293
  }
295
294
  else {
296
295
      g_debug("Property %s exists, but is not a string (is %s).",