From dfd713016ba4f1327e21b70d74de156f43fb5839 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 29 Jul 2019 22:36:39 +0200 Subject: [PATCH] Added some unit tests for performance improvement of queries. --- src/db/db/dbLayoutQuery.cc | 8 +++-- src/db/unit_tests/dbLayoutQueryTests.cc | 47 ++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/db/db/dbLayoutQuery.cc b/src/db/db/dbLayoutQuery.cc index bf0017292..ba99e4285 100644 --- a/src/db/db/dbLayoutQuery.cc +++ b/src/db/db/dbLayoutQuery.cc @@ -513,7 +513,7 @@ public: bool cell_matches (db::cell_index_type ci) { // prefilter with the cell objectives - if (! objectives ().wants_all_cells () && ! objectives ().wants_cell (ci)) { + if (! objectives ().wants_cell (ci)) { return false; } @@ -2960,6 +2960,10 @@ FilterStateObjectives::operator+= (const FilterStateObjectives &other) } } + if (m_wants_all_cells) { + m_wants_cells.clear (); + } + return *this; } @@ -2981,7 +2985,7 @@ FilterStateObjectives::request_cell (db::cell_index_type ci) bool FilterStateObjectives::wants_cell (db::cell_index_type ci) const { - return m_wants_cells.find (ci) != m_wants_cells.end (); + return m_wants_all_cells || m_wants_cells.find (ci) != m_wants_cells.end (); } // -------------------------------------------------------------------------------- diff --git a/src/db/unit_tests/dbLayoutQueryTests.cc b/src/db/unit_tests/dbLayoutQueryTests.cc index 7033ed379..46fbf22bd 100644 --- a/src/db/unit_tests/dbLayoutQueryTests.cc +++ b/src/db/unit_tests/dbLayoutQueryTests.cc @@ -117,7 +117,52 @@ static std::string q2s_cell (db::LayoutQueryIterator &iq, const std::string &pna return res; } -TEST(1) +TEST(0) +{ + // FilterStateObjectives tests + db::FilterStateObjectives o1; + + EXPECT_EQ (o1.wants_all_cells (), false); + o1.set_wants_all_cells (true); + EXPECT_EQ (o1.wants_cell (db::cell_index_type (17)), true); + EXPECT_EQ (o1.wants_all_cells (), true); + + o1.set_wants_all_cells (false); + o1.request_cell (db::cell_index_type (17)); + EXPECT_EQ (o1.wants_all_cells (), false); + EXPECT_EQ (o1.wants_cell (db::cell_index_type (17)), true); + EXPECT_EQ (o1.wants_cell (db::cell_index_type (16)), false); + + db::FilterStateObjectives o2 = o1; + + o1.set_wants_all_cells (false); + EXPECT_EQ (o1.wants_cell (db::cell_index_type (17)), false); + + EXPECT_EQ (o2.wants_cell (db::cell_index_type (17)), true); + + db::FilterStateObjectives o3 = o2; + + EXPECT_EQ (o3.wants_cell (db::cell_index_type (17)), true); + o3 += db::FilterStateObjectives::everything (); + EXPECT_EQ (o3.wants_all_cells (), true); + + o3 = db::FilterStateObjectives::everything (); + EXPECT_EQ (o3.wants_all_cells (), true); + o3 += o2; + EXPECT_EQ (o3.wants_all_cells (), true); + + o3 = db::FilterStateObjectives (); + EXPECT_EQ (o3.wants_all_cells (), false); + o3.request_cell (db::cell_index_type (16)); + EXPECT_EQ (o3.wants_cell (db::cell_index_type (17)), false); + EXPECT_EQ (o3.wants_cell (db::cell_index_type (16)), true); + o3 += o2; + EXPECT_EQ (o3.wants_all_cells (), false); + EXPECT_EQ (o3.wants_cell (db::cell_index_type (17)), true); + EXPECT_EQ (o3.wants_cell (db::cell_index_type (16)), true); +} + +TEST(1) { db::Layout g; g.insert_layer (0);