From e1cb2c0f404d9fe68f5f465a281be295ca24ec33 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 14 May 2019 04:22:51 +0000 Subject: [Object] Change ObjectFile::getSectionContents to return Expected> Change std::error_code getSectionContents(DataRefImpl, StringRef &) const; to Expected> getSectionContents(DataRefImpl) const; Many object formats use ArrayRef as the underlying type, which is generally better than StringRef to represent binary data, so change the type to decrease the number of type conversions. Reviewed By: ruiu, sbc100 Differential Revision: https://reviews.llvm.org/D61781 llvm-svn: 360648 --- llvm/lib/Object/WasmObjectFile.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Object/WasmObjectFile.cpp') diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 1c56ee6652a..82aa1830dce 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -1427,14 +1427,12 @@ uint64_t WasmObjectFile::getSectionSize(DataRefImpl Sec) const { return S.Content.size(); } -std::error_code WasmObjectFile::getSectionContents(DataRefImpl Sec, - StringRef &Res) const { +Expected> +WasmObjectFile::getSectionContents(DataRefImpl Sec) const { const WasmSection &S = Sections[Sec.d.a]; // This will never fail since wasm sections can never be empty (user-sections // must have a name and non-user sections each have a defined structure). - Res = StringRef(reinterpret_cast(S.Content.data()), - S.Content.size()); - return std::error_code(); + return S.Content; } uint64_t WasmObjectFile::getSectionAlignment(DataRefImpl Sec) const { -- cgit v1.2.3