Thumb2: Fix EmitJumpTables() to extend buffer only if needed.
Bug: 28256882
Change-Id: I15227535c0fcb73c04b0b05160852c4b1bebee49
diff --git a/compiler/utils/arm/assembler_thumb2.cc b/compiler/utils/arm/assembler_thumb2.cc
index 26f7d0d..2c73fb8 100644
--- a/compiler/utils/arm/assembler_thumb2.cc
+++ b/compiler/utils/arm/assembler_thumb2.cc
@@ -256,7 +256,10 @@
for (JumpTable& table : jump_tables_) {
// Bulk ensure capacity, as this may be large.
size_t orig_size = buffer_.Size();
- buffer_.ExtendCapacity(orig_size + table.GetSize());
+ size_t required_capacity = orig_size + table.GetSize();
+ if (required_capacity > buffer_.Capacity()) {
+ buffer_.ExtendCapacity(required_capacity);
+ }
#ifndef NDEBUG
buffer_.has_ensured_capacity_ = true;
#endif