From 3ab76b7ec20f4164ac2d9fdca071acc511119c59 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 5 Oct 2011 19:56:19 -0400 Subject: [PATCH] Bug 691909 - Avoid an unnecessary memory allocation for GTK clipboard code; r=roc --HG-- extra : rebase_source : 2d4ae14de525809bded55e235867b058993f6c94 --- widget/src/gtk2/nsClipboard.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/widget/src/gtk2/nsClipboard.cpp b/widget/src/gtk2/nsClipboard.cpp index 7196932ee15..5532bfbeb18 100644 --- a/widget/src/gtk2/nsClipboard.cpp +++ b/widget/src/gtk2/nsClipboard.cpp @@ -953,7 +953,6 @@ clipboard_contents_received(GtkClipboard *clipboard, { retrieval_context *context = static_cast(data); if (context->timed_out) { - delete context; return; } @@ -967,20 +966,16 @@ clipboard_contents_received(GtkClipboard *clipboard, static GtkSelectionData * wait_for_contents(GtkClipboard *clipboard, GdkAtom target) { - retrieval_context *context = new retrieval_context(); + retrieval_context context; gtk_clipboard_request_contents(clipboard, target, clipboard_contents_received, - context); + &context); - if (!wait_for_retrieval(clipboard, context)) { - // Don't delete |context|; the callback will when it eventually - // comes back. + if (!wait_for_retrieval(clipboard, &context)) { return nsnull; } - GtkSelectionData *result = static_cast(context->data); - delete context; - return result; + return static_cast(context.data); } static void @@ -990,7 +985,6 @@ clipboard_text_received(GtkClipboard *clipboard, { retrieval_context *context = static_cast(data); if (context->timed_out) { - delete context; return; } @@ -1001,16 +995,12 @@ clipboard_text_received(GtkClipboard *clipboard, static gchar * wait_for_text(GtkClipboard *clipboard) { - retrieval_context *context = new retrieval_context(); - gtk_clipboard_request_text(clipboard, clipboard_text_received, context); + retrieval_context context; + gtk_clipboard_request_text(clipboard, clipboard_text_received, &context); - if (!wait_for_retrieval(clipboard, context)) { - // Don't delete |context|; the callback will when it eventually - // comes back. + if (!wait_for_retrieval(clipboard, &context)) { return nsnull; } - gchar *result = static_cast(context->data); - delete context; - return result; + return static_cast(context.data); }