From 1aa246dec5abe212f699de1413a0c4a191ca364a Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 13 Dec 2012 09:29:36 -0800 Subject: Move casts.h and stl_util.h into base/. Change-Id: Idb3bfa5cec3d146e488031d91265737cde2b4cf4 --- src/atomic.cc | 2 +- src/base/casts.h | 93 ++++++++++++++++++++++++++++ src/base/stl_util.h | 97 ++++++++++++++++++++++++++++++ src/casts.h | 93 ---------------------------- src/class_linker.cc | 4 +- src/common_test.h | 2 +- src/compiler.cc | 2 +- src/compiler_llvm/compiler_llvm.cc | 2 +- src/compiler_llvm/method_compiler.cc | 2 +- src/constants_arm.h | 2 +- src/dex2oat.cc | 2 +- src/gc/large_object_space.cc | 2 +- src/gc/mod_union_table.cc | 5 +- src/gc/space.cc | 4 +- src/greenland/inferred_reg_category_map.cc | 5 +- src/heap.cc | 2 +- src/jni_internal.cc | 2 +- src/monitor.cc | 2 +- src/oat/utils/mips/assembler_mips.cc | 2 +- src/oat/utils/x86/assembler_x86.cc | 2 +- src/oat_file.cc | 2 +- src/oat_writer.cc | 2 +- src/object.h | 2 +- src/scoped_thread_state_change.h | 2 +- src/stl_util.h | 97 ------------------------------ src/thread_pool.cc | 23 ++++++- src/verifier/method_verifier.h | 4 +- src/verifier/reg_type_cache.h | 2 +- 28 files changed, 240 insertions(+), 221 deletions(-) create mode 100644 src/base/casts.h create mode 100644 src/base/stl_util.h delete mode 100644 src/casts.h delete mode 100644 src/stl_util.h (limited to 'src') diff --git a/src/atomic.cc b/src/atomic.cc index 5cc750d701..480e456b78 100644 --- a/src/atomic.cc +++ b/src/atomic.cc @@ -20,7 +20,7 @@ #include #include "base/mutex.h" -#include "stl_util.h" +#include "base/stl_util.h" #include "stringprintf.h" #include "thread.h" diff --git a/src/base/casts.h b/src/base/casts.h new file mode 100644 index 0000000000..34c05af4e3 --- /dev/null +++ b/src/base/casts.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_SRC_BASE_CASTS_H_ +#define ART_SRC_BASE_CASTS_H_ + +#include +#include +#include "base/macros.h" + +namespace art { + +// Use implicit_cast as a safe version of static_cast or const_cast +// for upcasting in the type hierarchy (i.e. casting a pointer to Foo +// to a pointer to SuperclassOfFoo or casting a pointer to Foo to +// a const pointer to Foo). +// When you use implicit_cast, the compiler checks that the cast is safe. +// Such explicit implicit_casts are necessary in surprisingly many +// situations where C++ demands an exact type match instead of an +// argument type convertable to a target type. +// +// The From type can be inferred, so the preferred syntax for using +// implicit_cast is the same as for static_cast etc.: +// +// implicit_cast(expr) +// +// implicit_cast would have been part of the C++ standard library, +// but the proposal was submitted too late. It will probably make +// its way into the language in the future. +template +inline To implicit_cast(From const &f) { + return f; +} + +// When you upcast (that is, cast a pointer from type Foo to type +// SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts +// always succeed. When you downcast (that is, cast a pointer from +// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because +// how do you know the pointer is really of type SubclassOfFoo? It +// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, +// when you downcast, you should use this macro. In debug mode, we +// use dynamic_cast<> to double-check the downcast is legal (we die +// if it's not). In normal mode, we do the efficient static_cast<> +// instead. Thus, it's important to test in debug mode to make sure +// the cast is legal! +// This is the only place in the code we should use dynamic_cast<>. +// In particular, you SHOULDN'T be using dynamic_cast<> in order to +// do RTTI (eg code like this: +// if (dynamic_cast(foo)) HandleASubclass1Object(foo); +// if (dynamic_cast(foo)) HandleASubclass2Object(foo); +// You should design the code some other way not to need this. + +template // use like this: down_cast(foo); +inline To down_cast(From* f) { // so we only accept pointers + // Ensures that To is a sub-type of From *. This test is here only + // for compile-time type checking, and has no overhead in an + // optimized build at run-time, as it will be optimized away + // completely. + if (false) { + implicit_cast(0); + } + + // + // assert(f == NULL || dynamic_cast(f) != NULL); // RTTI: debug mode only! + return static_cast(f); +} + +template +inline Dest bit_cast(const Source& source) { + // Compile time assertion: sizeof(Dest) == sizeof(Source) + // A compile error here means your Dest and Source have different sizes. + COMPILE_ASSERT(sizeof(Dest) == sizeof(Source), verify_sizes_are_equal); + Dest dest; + memcpy(&dest, &source, sizeof(dest)); + return dest; +} + +} // namespace art + +#endif // ART_SRC_BASE_CASTS_H_ diff --git a/src/base/stl_util.h b/src/base/stl_util.h new file mode 100644 index 0000000000..eb8be42df3 --- /dev/null +++ b/src/base/stl_util.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_SRC_BASE_STL_UTIL_H_ +#define ART_SRC_BASE_STL_UTIL_H_ + +#include +#include + +namespace art { + +// Sort and remove duplicates of an STL vector or deque. +template +void STLSortAndRemoveDuplicates(T* v) { + std::sort(v->begin(), v->end()); + v->erase(std::unique(v->begin(), v->end()), v->end()); +} + +// STLDeleteContainerPointers() +// For a range within a container of pointers, calls delete +// (non-array version) on these pointers. +// NOTE: for these three functions, we could just implement a DeleteObject +// functor and then call for_each() on the range and functor, but this +// requires us to pull in all of algorithm.h, which seems expensive. +// For hash_[multi]set, it is important that this deletes behind the iterator +// because the hash_set may call the hash function on the iterator when it is +// advanced, which could result in the hash function trying to deference a +// stale pointer. +template +void STLDeleteContainerPointers(ForwardIterator begin, + ForwardIterator end) { + while (begin != end) { + ForwardIterator temp = begin; + ++begin; + delete *temp; + } +} + +// STLDeleteElements() deletes all the elements in an STL container and clears +// the container. This function is suitable for use with a vector, set, +// hash_set, or any other STL container which defines sensible begin(), end(), +// and clear() methods. +// +// If container is NULL, this function is a no-op. +// +// As an alternative to calling STLDeleteElements() directly, consider +// ElementDeleter (defined below), which ensures that your container's elements +// are deleted when the ElementDeleter goes out of scope. +template +void STLDeleteElements(T *container) { + if (!container) return; + STLDeleteContainerPointers(container->begin(), container->end()); + container->clear(); +} + +// Given an STL container consisting of (key, value) pairs, STLDeleteValues +// deletes all the "value" components and clears the container. Does nothing +// in the case it's given a NULL pointer. +template +void STLDeleteValues(T *v) { + if (!v) return; + for (typename T::iterator i = v->begin(); i != v->end(); ++i) { + delete i->second; + } + v->clear(); +} + +template +std::string ToString(const T& v) { + std::ostringstream os; + os << "["; + for (size_t i = 0; i < v.size(); ++i) { + os << v[i]; + if (i < v.size() - 1) { + os << ", "; + } + } + os << "]"; + return os.str(); +} + +} // namespace art + +#endif // ART_SRC_BASE_STL_UTIL_H_ diff --git a/src/casts.h b/src/casts.h deleted file mode 100644 index f996dcd6fd..0000000000 --- a/src/casts.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ART_SRC_CASTS_H_ -#define ART_SRC_CASTS_H_ - -#include -#include -#include "base/macros.h" - -namespace art { - -// Use implicit_cast as a safe version of static_cast or const_cast -// for upcasting in the type hierarchy (i.e. casting a pointer to Foo -// to a pointer to SuperclassOfFoo or casting a pointer to Foo to -// a const pointer to Foo). -// When you use implicit_cast, the compiler checks that the cast is safe. -// Such explicit implicit_casts are necessary in surprisingly many -// situations where C++ demands an exact type match instead of an -// argument type convertable to a target type. -// -// The From type can be inferred, so the preferred syntax for using -// implicit_cast is the same as for static_cast etc.: -// -// implicit_cast(expr) -// -// implicit_cast would have been part of the C++ standard library, -// but the proposal was submitted too late. It will probably make -// its way into the language in the future. -template -inline To implicit_cast(From const &f) { - return f; -} - -// When you upcast (that is, cast a pointer from type Foo to type -// SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts -// always succeed. When you downcast (that is, cast a pointer from -// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because -// how do you know the pointer is really of type SubclassOfFoo? It -// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, -// when you downcast, you should use this macro. In debug mode, we -// use dynamic_cast<> to double-check the downcast is legal (we die -// if it's not). In normal mode, we do the efficient static_cast<> -// instead. Thus, it's important to test in debug mode to make sure -// the cast is legal! -// This is the only place in the code we should use dynamic_cast<>. -// In particular, you SHOULDN'T be using dynamic_cast<> in order to -// do RTTI (eg code like this: -// if (dynamic_cast(foo)) HandleASubclass1Object(foo); -// if (dynamic_cast(foo)) HandleASubclass2Object(foo); -// You should design the code some other way not to need this. - -template // use like this: down_cast(foo); -inline To down_cast(From* f) { // so we only accept pointers - // Ensures that To is a sub-type of From *. This test is here only - // for compile-time type checking, and has no overhead in an - // optimized build at run-time, as it will be optimized away - // completely. - if (false) { - implicit_cast(0); - } - - // - // assert(f == NULL || dynamic_cast(f) != NULL); // RTTI: debug mode only! - return static_cast(f); -} - -template -inline Dest bit_cast(const Source& source) { - // Compile time assertion: sizeof(Dest) == sizeof(Source) - // A compile error here means your Dest and Source have different sizes. - COMPILE_ASSERT(sizeof(Dest) == sizeof(Source), verify_sizes_are_equal); - Dest dest; - memcpy(&dest, &source, sizeof(dest)); - return dest; -} - -} // namespace art - -#endif // ART_SRC_CASTS_H_ diff --git a/src/class_linker.cc b/src/class_linker.cc index 626b1d9fad..ca8a53287a 100644 --- a/src/class_linker.cc +++ b/src/class_linker.cc @@ -27,9 +27,10 @@ #include #include +#include "base/casts.h" #include "base/logging.h" +#include "base/stl_util.h" #include "base/unix_file/fd_file.h" -#include "casts.h" #include "class_loader.h" #include "debugger.h" #include "dex_cache.h" @@ -53,7 +54,6 @@ #include "gc/space.h" #include "gc/space_bitmap.h" #include "stack_indirect_reference_table.h" -#include "stl_util.h" #include "thread.h" #include "UniquePtr.h" #include "utils.h" diff --git a/src/common_test.h b/src/common_test.h index e4996a31a0..60f665a119 100644 --- a/src/common_test.h +++ b/src/common_test.h @@ -22,6 +22,7 @@ #include "../../external/icu4c/common/unicode/uvernum.h" #include "base/macros.h" +#include "base/stl_util.h" #include "base/unix_file/fd_file.h" #include "class_linker.h" #include "class_loader.h" @@ -36,7 +37,6 @@ #include "runtime.h" #include "ScopedLocalRef.h" #include "scoped_thread_state_change.h" -#include "stl_util.h" #include "stringprintf.h" #include "thread.h" #include "UniquePtr.h" diff --git a/src/compiler.cc b/src/compiler.cc index 522b8c844f..b125fdf68c 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -21,6 +21,7 @@ #include #include +#include "base/stl_util.h" #include "class_linker.h" #include "class_loader.h" #include "dex_cache.h" @@ -33,7 +34,6 @@ #include "gc/space.h" #include "scoped_thread_state_change.h" #include "ScopedLocalRef.h" -#include "stl_util.h" #include "thread.h" #include "thread_pool.h" #include "timing_logger.h" diff --git a/src/compiler_llvm/compiler_llvm.cc b/src/compiler_llvm/compiler_llvm.cc index 78434072ee..954e2f420b 100644 --- a/src/compiler_llvm/compiler_llvm.cc +++ b/src/compiler_llvm/compiler_llvm.cc @@ -16,6 +16,7 @@ #include "compiler_llvm.h" +#include "base/stl_util.h" #include "backend_options.h" #include "class_linker.h" #include "compilation_unit.h" @@ -28,7 +29,6 @@ #endif #include "oat_compilation_unit.h" #include "oat_file.h" -#include "stl_util.h" #include "stub_compiler.h" #include "utils_llvm.h" #include "verifier/method_verifier.h" diff --git a/src/compiler_llvm/method_compiler.cc b/src/compiler_llvm/method_compiler.cc index d9897289e7..52fb02c118 100644 --- a/src/compiler_llvm/method_compiler.cc +++ b/src/compiler_llvm/method_compiler.cc @@ -18,6 +18,7 @@ #include "backend_types.h" #include "base/logging.h" +#include "base/stl_util.h" #include "compilation_unit.h" #include "compiler.h" #include "dalvik_reg.h" @@ -28,7 +29,6 @@ #include "object_utils.h" #include "runtime_support_func.h" #include "runtime_support_llvm.h" -#include "stl_util.h" #include "stringprintf.h" #include "utils_llvm.h" #include "verifier/method_verifier.h" diff --git a/src/constants_arm.h b/src/constants_arm.h index 022bc6e8db..601c57247e 100644 --- a/src/constants_arm.h +++ b/src/constants_arm.h @@ -21,8 +21,8 @@ #include +#include "base/casts.h" #include "base/logging.h" -#include "casts.h" #include "globals.h" namespace art { diff --git a/src/dex2oat.cc b/src/dex2oat.cc index 550f857c5d..70b2a6ba71 100644 --- a/src/dex2oat.cc +++ b/src/dex2oat.cc @@ -23,6 +23,7 @@ #include #include +#include "base/stl_util.h" #include "base/unix_file/fd_file.h" #include "class_linker.h" #include "class_loader.h" @@ -36,7 +37,6 @@ #include "ScopedLocalRef.h" #include "scoped_thread_state_change.h" #include "sirt_ref.h" -#include "stl_util.h" #include "stringpiece.h" #include "timing_logger.h" #include "well_known_classes.h" diff --git a/src/gc/large_object_space.cc b/src/gc/large_object_space.cc index 0247e8de82..1b93e5d570 100644 --- a/src/gc/large_object_space.cc +++ b/src/gc/large_object_space.cc @@ -15,13 +15,13 @@ */ #include "base/logging.h" +#include "base/stl_util.h" #include "large_object_space.h" #include "UniquePtr.h" #include "dlmalloc.h" #include "image.h" #include "os.h" #include "space_bitmap.h" -#include "stl_util.h" #include "utils.h" namespace art { diff --git a/src/gc/mod_union_table.cc b/src/gc/mod_union_table.cc index 4d9ffe245b..8953c5ac61 100644 --- a/src/gc/mod_union_table.cc +++ b/src/gc/mod_union_table.cc @@ -14,12 +14,13 @@ * limitations under the License. */ +#include "mod_union_table.h" + +#include "base/stl_util.h" #include "heap.h" #include "heap_bitmap.h" #include "mark_sweep.h" -#include "mod_union_table.h" #include "space.h" -#include "stl_util.h" #include "UniquePtr.h" namespace art { diff --git a/src/gc/space.cc b/src/gc/space.cc index bf25358b02..37565db7fc 100644 --- a/src/gc/space.cc +++ b/src/gc/space.cc @@ -16,14 +16,14 @@ #include "space.h" -#include "UniquePtr.h" #include "base/logging.h" +#include "base/stl_util.h" #include "base/unix_file/fd_file.h" #include "dlmalloc.h" #include "image.h" #include "os.h" #include "space_bitmap.h" -#include "stl_util.h" +#include "UniquePtr.h" #include "utils.h" namespace art { diff --git a/src/greenland/inferred_reg_category_map.cc b/src/greenland/inferred_reg_category_map.cc index 0c31634762..b4ce12c94a 100644 --- a/src/greenland/inferred_reg_category_map.cc +++ b/src/greenland/inferred_reg_category_map.cc @@ -16,11 +16,12 @@ #include "inferred_reg_category_map.h" -#include "stl_util.h" - #include + #include +#include "base/stl_util.h" + namespace art { namespace greenland { diff --git a/src/heap.cc b/src/heap.cc index 13f6ee8fc1..7edbcf0460 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -22,6 +22,7 @@ #include #include +#include "base/stl_util.h" #include "debugger.h" #include "gc/atomic_stack.h" #include "gc/card_table.h" @@ -39,7 +40,6 @@ #include "ScopedLocalRef.h" #include "scoped_thread_state_change.h" #include "sirt_ref.h" -#include "stl_util.h" #include "thread_list.h" #include "timing_logger.h" #include "UniquePtr.h" diff --git a/src/jni_internal.cc b/src/jni_internal.cc index db72a9938b..fc7bdd4407 100644 --- a/src/jni_internal.cc +++ b/src/jni_internal.cc @@ -24,6 +24,7 @@ #include "base/logging.h" #include "base/mutex.h" +#include "base/stl_util.h" #include "class_linker.h" #include "class_loader.h" #include "invoke_arg_array_builder.h" @@ -34,7 +35,6 @@ #include "safe_map.h" #include "scoped_thread_state_change.h" #include "ScopedLocalRef.h" -#include "stl_util.h" #include "stringpiece.h" #include "thread.h" #include "UniquePtr.h" diff --git a/src/monitor.cc b/src/monitor.cc index d58f462c9e..6172136d4a 100644 --- a/src/monitor.cc +++ b/src/monitor.cc @@ -19,12 +19,12 @@ #include #include "base/mutex.h" +#include "base/stl_util.h" #include "class_linker.h" #include "dex_instruction.h" #include "object.h" #include "object_utils.h" #include "scoped_thread_state_change.h" -#include "stl_util.h" #include "thread.h" #include "thread_list.h" #include "verifier/method_verifier.h" diff --git a/src/oat/utils/mips/assembler_mips.cc b/src/oat/utils/mips/assembler_mips.cc index be1aceb077..25ba9b2219 100644 --- a/src/oat/utils/mips/assembler_mips.cc +++ b/src/oat/utils/mips/assembler_mips.cc @@ -16,7 +16,7 @@ #include "assembler_mips.h" -#include "casts.h" +#include "base/casts.h" #include "memory_region.h" #include "oat/runtime/oat_support_entrypoints.h" #include "thread.h" diff --git a/src/oat/utils/x86/assembler_x86.cc b/src/oat/utils/x86/assembler_x86.cc index 010318b03a..fd8f152c54 100644 --- a/src/oat/utils/x86/assembler_x86.cc +++ b/src/oat/utils/x86/assembler_x86.cc @@ -16,7 +16,7 @@ #include "assembler_x86.h" -#include "casts.h" +#include "base/casts.h" #include "memory_region.h" #include "oat/runtime/oat_support_entrypoints.h" #include "thread.h" diff --git a/src/oat_file.cc b/src/oat_file.cc index d3e1079fb2..b201630c64 100644 --- a/src/oat_file.cc +++ b/src/oat_file.cc @@ -16,9 +16,9 @@ #include "oat_file.h" +#include "base/stl_util.h" #include "base/unix_file/fd_file.h" #include "os.h" -#include "stl_util.h" namespace art { diff --git a/src/oat_writer.cc b/src/oat_writer.cc index 49d4e253bd..284578b024 100644 --- a/src/oat_writer.cc +++ b/src/oat_writer.cc @@ -18,6 +18,7 @@ #include +#include "base/stl_util.h" #include "base/unix_file/fd_file.h" #include "class_linker.h" #include "class_loader.h" @@ -25,7 +26,6 @@ #include "safe_map.h" #include "scoped_thread_state_change.h" #include "gc/space.h" -#include "stl_util.h" #include "verifier/method_verifier.h" namespace art { diff --git a/src/object.h b/src/object.h index f577f0ab39..2ae3ac1096 100644 --- a/src/object.h +++ b/src/object.h @@ -22,9 +22,9 @@ #include "UniquePtr.h" #include "atomic.h" +#include "base/casts.h" #include "base/logging.h" #include "base/macros.h" -#include "casts.h" #include "globals.h" #include "heap.h" #include "invoke_type.h" diff --git a/src/scoped_thread_state_change.h b/src/scoped_thread_state_change.h index c0fb649b68..5eabbdf09f 100644 --- a/src/scoped_thread_state_change.h +++ b/src/scoped_thread_state_change.h @@ -17,7 +17,7 @@ #ifndef ART_SRC_SCOPED_THREAD_STATE_CHANGE_H_ #define ART_SRC_SCOPED_THREAD_STATE_CHANGE_H_ -#include "casts.h" +#include "base/casts.h" #include "jni_internal.h" #include "thread.h" diff --git a/src/stl_util.h b/src/stl_util.h deleted file mode 100644 index 1282cc4230..0000000000 --- a/src/stl_util.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ART_SRC_STL_UTIL_H_ -#define ART_SRC_STL_UTIL_H_ - -#include -#include - -namespace art { - -// Sort and remove duplicates of an STL vector or deque. -template -void STLSortAndRemoveDuplicates(T* v) { - std::sort(v->begin(), v->end()); - v->erase(std::unique(v->begin(), v->end()), v->end()); -} - -// STLDeleteContainerPointers() -// For a range within a container of pointers, calls delete -// (non-array version) on these pointers. -// NOTE: for these three functions, we could just implement a DeleteObject -// functor and then call for_each() on the range and functor, but this -// requires us to pull in all of algorithm.h, which seems expensive. -// For hash_[multi]set, it is important that this deletes behind the iterator -// because the hash_set may call the hash function on the iterator when it is -// advanced, which could result in the hash function trying to deference a -// stale pointer. -template -void STLDeleteContainerPointers(ForwardIterator begin, - ForwardIterator end) { - while (begin != end) { - ForwardIterator temp = begin; - ++begin; - delete *temp; - } -} - -// STLDeleteElements() deletes all the elements in an STL container and clears -// the container. This function is suitable for use with a vector, set, -// hash_set, or any other STL container which defines sensible begin(), end(), -// and clear() methods. -// -// If container is NULL, this function is a no-op. -// -// As an alternative to calling STLDeleteElements() directly, consider -// ElementDeleter (defined below), which ensures that your container's elements -// are deleted when the ElementDeleter goes out of scope. -template -void STLDeleteElements(T *container) { - if (!container) return; - STLDeleteContainerPointers(container->begin(), container->end()); - container->clear(); -} - -// Given an STL container consisting of (key, value) pairs, STLDeleteValues -// deletes all the "value" components and clears the container. Does nothing -// in the case it's given a NULL pointer. -template -void STLDeleteValues(T *v) { - if (!v) return; - for (typename T::iterator i = v->begin(); i != v->end(); ++i) { - delete i->second; - } - v->clear(); -} - -template -std::string ToString(const T& v) { - std::ostringstream os; - os << "["; - for (size_t i = 0; i < v.size(); ++i) { - os << v[i]; - if (i < v.size() - 1) { - os << ", "; - } - } - os << "]"; - return os.str(); -} - -} // namespace art - -#endif // ART_SRC_STL_UTIL_H_ diff --git a/src/thread_pool.cc b/src/thread_pool.cc index 1686ea6368..a06f9d3bff 100644 --- a/src/thread_pool.cc +++ b/src/thread_pool.cc @@ -1,8 +1,25 @@ -#include "casts.h" +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "thread_pool.h" + +#include "base/casts.h" +#include "base/stl_util.h" #include "runtime.h" -#include "stl_util.h" #include "thread.h" -#include "thread_pool.h" namespace art { diff --git a/src/verifier/method_verifier.h b/src/verifier/method_verifier.h index 99801c6f5d..b6762692eb 100644 --- a/src/verifier/method_verifier.h +++ b/src/verifier/method_verifier.h @@ -22,8 +22,9 @@ #include #include +#include "base/casts.h" #include "base/macros.h" -#include "casts.h" +#include "base/stl_util.h" #include "compiler.h" #include "dex_file.h" #include "dex_instruction.h" @@ -32,7 +33,6 @@ #include "reg_type_cache.h" #include "register_line.h" #include "safe_map.h" -#include "stl_util.h" #include "UniquePtr.h" namespace art { diff --git a/src/verifier/reg_type_cache.h b/src/verifier/reg_type_cache.h index c86f65b2de..1cd3fba0bd 100644 --- a/src/verifier/reg_type_cache.h +++ b/src/verifier/reg_type_cache.h @@ -18,8 +18,8 @@ #define ART_SRC_VERIFIER_REG_TYPE_CACHE_H_ #include "base/macros.h" +#include "base/stl_util.h" #include "reg_type.h" -#include "stl_util.h" namespace art { namespace verifier { -- cgit v1.2.3-59-g8ed1b