From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 9172E6DE0243 for ; Sat, 28 Jan 2017 05:15:41 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=0.006, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lZz3lLDo1Ojc for ; Sat, 28 Jan 2017 05:15:40 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 8BB036DE00AC for ; Sat, 28 Jan 2017 05:15:40 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1cXSqS-0007uM-GN; Sat, 28 Jan 2017 08:15:08 -0500 Received: (nullmailer pid 26486 invoked by uid 1000); Sat, 28 Jan 2017 13:15:38 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [RFC Patch 2/2] lib: Let Xapian manage the memory for FieldProcessors Date: Sat, 28 Jan 2017 09:15:21 -0400 Message-Id: <20170128131521.26414-3-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170128131521.26414-1-david@tethera.net> References: <20170128131521.26414-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Jan 2017 13:15:41 -0000 It turns out this is exactly what release() is for; Xapian will deallocate the objects when it's done with them. --- lib/database-private.h | 4 ---- lib/database.cc | 19 ++++++++----------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/database-private.h b/lib/database-private.h index 32357ce0..3eac3c7e 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -194,10 +194,6 @@ struct _notmuch_database { Xapian::TermGenerator *term_gen; Xapian::ValueRangeProcessor *value_range_processor; Xapian::ValueRangeProcessor *date_range_processor; -#if HAVE_XAPIAN_FIELD_PROCESSOR - Xapian::FieldProcessor *date_field_processor; - Xapian::FieldProcessor *query_field_processor; -#endif Xapian::ValueRangeProcessor *last_mod_range_processor; }; diff --git a/lib/database.cc b/lib/database.cc index b98468a6..c1563ca7 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1029,10 +1029,14 @@ notmuch_database_open_verbose (const char *path, #if HAVE_XAPIAN_FIELD_PROCESSOR /* This currently relies on the query parser to pass anything * with a .. to the range processor */ - notmuch->date_field_processor = new DateFieldProcessor(); - notmuch->query_parser->add_boolean_prefix("date", notmuch->date_field_processor); - notmuch->query_field_processor = new QueryFieldProcessor (*notmuch->query_parser, notmuch); - notmuch->query_parser->add_boolean_prefix("query", notmuch->query_field_processor); + { + Xapian::FieldProcessor * date_fp = new DateFieldProcessor(); + Xapian::FieldProcessor * query_fp = + new QueryFieldProcessor (*notmuch->query_parser, notmuch); + + notmuch->query_parser->add_boolean_prefix("date", date_fp->release ()); + notmuch->query_parser->add_boolean_prefix("query", query_fp->release ()); + } #endif notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:"); @@ -1125,13 +1129,6 @@ notmuch_database_close (notmuch_database_t *notmuch) delete notmuch->last_mod_range_processor; notmuch->last_mod_range_processor = NULL; -#if HAVE_XAPIAN_FIELD_PROCESSOR - delete notmuch->date_field_processor; - notmuch->date_field_processor = NULL; - delete notmuch->query_field_processor; - notmuch->query_field_processor = NULL; -#endif - return status; } -- 2.11.0