From 7c1b44731ed3fe7f973c386b849fc3dd76d1cced Mon Sep 17 00:00:00 2001 From: wuyongkang Date: Thu, 16 Jul 2020 09:43:36 +0800 Subject: [PATCH] Optimization for map_data_.clear() --- mindspore/ccsrc/utils/ordered_map.h | 4 +++- mindspore/ccsrc/utils/ordered_set.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mindspore/ccsrc/utils/ordered_map.h b/mindspore/ccsrc/utils/ordered_map.h index 48aa36df31..56ae281dcf 100644 --- a/mindspore/ccsrc/utils/ordered_map.h +++ b/mindspore/ccsrc/utils/ordered_map.h @@ -88,7 +88,9 @@ class OrderedMap { } void clear() { - map_data_.clear(); + if (!map_data_.empty()) { + map_data_.clear(); + } sequential_data_.clear(); } diff --git a/mindspore/ccsrc/utils/ordered_set.h b/mindspore/ccsrc/utils/ordered_set.h index f393ce74f2..8d2f7af15c 100644 --- a/mindspore/ccsrc/utils/ordered_set.h +++ b/mindspore/ccsrc/utils/ordered_set.h @@ -127,7 +127,9 @@ class OrderedSet { // Clear the elements void clear() { - mapped_data_.clear(); + if (!mapped_data_.empty()) { + mapped_data_.clear(); + } ordered_data_.clear(); }