diff options
author | Ian Rogers <irogers@google.com> | 2013-08-09 22:05:32 -0700 |
---|---|---|
committer | Ian Rogers <irogers@google.com> | 2013-08-12 06:16:03 +0000 |
commit | 96faf5b363d922ae91cf25404dee0e87c740c7c5 (patch) | |
tree | d397fd63cde72e897490e21b3af3c355db7a36d4 /compiler/leb128_encoder.h | |
parent | 49bded21270e8087e11d933d7b19aee22c0d8649 (diff) | |
download | art-96faf5b363d922ae91cf25404dee0e87c740c7c5.zip art-96faf5b363d922ae91cf25404dee0e87c740c7c5.tar.gz art-96faf5b363d922ae91cf25404dee0e87c740c7c5.tar.bz2 |
Uleb128 compression of vmap and mapping table.
Bug 9437697.
Change-Id: I30bcb97d12cd8b46d3b2cdcbdd358f08fbb9947a
(cherry picked from commit 1809a72a66d245ae598582d658b93a24ac3bf01e)
Diffstat (limited to 'compiler/leb128_encoder.h')
-rw-r--r-- | compiler/leb128_encoder.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/compiler/leb128_encoder.h b/compiler/leb128_encoder.h new file mode 100644 index 0000000..e9a1c32 --- /dev/null +++ b/compiler/leb128_encoder.h @@ -0,0 +1,63 @@ +/* + * 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_COMPILER_LEB128_ENCODER_H_ +#define ART_COMPILER_LEB128_ENCODER_H_ + +#include "base/macros.h" + +namespace art { + +// An encoder with an API similar to vector<uint32_t> where the data is captured in ULEB128 format. +class UnsignedLeb128EncodingVector { + public: + UnsignedLeb128EncodingVector() { + } + + void PushBack(uint32_t value) { + bool done = false; + do { + uint8_t out = value & 0x7f; + if (out != value) { + data_.push_back(out | 0x80); + value >>= 7; + } else { + data_.push_back(out); + done = true; + } + } while (!done); + } + + template<typename It> + void InsertBack(It cur, It end) { + for (; cur != end; ++cur) { + PushBack(*cur); + } + } + + const std::vector<uint8_t>& GetData() const { + return data_; + } + + private: + std::vector<uint8_t> data_; + + DISALLOW_COPY_AND_ASSIGN(UnsignedLeb128EncodingVector); +}; + +} // namespace art + +#endif // ART_COMPILER_LEB128_ENCODER_H_ |