8000 absl::string_view -> std::string_view by haberman · Pull Request #399 · google/bloaty · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

absl::string_view -> std::string_view #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
id: llvm-revision
run: |
echo "revision=$(git -C ${{ github.workspace }}/llvm-project rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v2
- uses: actions/cache@v4
id: llvm-build
with:
path: ${{ github.workspace }}/build/llvm-project
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
id: llvm-revision
run: |
echo "revision=$(git -C ${{ github.workspace }}/llvm-project rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v2
- uses: actions/cache@v4
id: llvm-build
with:
path: ${{ github.workspace }}/build/llvm-project
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
id: llvm-revision
run: |
echo "revision=$(git -C ${{ github.workspace }}/llvm-project rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v2
- uses: actions/cache@v4
id: llvm-build
with:
path: ${{ github.workspace }}/build/llvm-project
Expand Down
2 changes: 8000 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/bloaty
!tests/testdata/**
*.dSYM
build
build-*
27 changes: 14 additions & 13 deletions src/bloaty.cc
6D47
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ typedef size_t z_size_t;
#include <mutex>
#include <sstream>
#include <string>
#include <string_view>
#include <thread>
#include <unordered_map>
#include <vector>

#if !defined(_WIN32)
#include <sys/mman.h>
#include <sys/wait.h>
Expand All @@ -53,7 +55,6 @@ typedef size_t z_size_t;
#include "absl/memory/memory.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "bloaty.h"
#include "bloaty.pb.h"
Expand All @@ -62,7 +63,7 @@ typedef size_t z_size_t;
#include "re.h"
#include "util.h"

using absl::string_view;
using std::string_view;

namespace bloaty {

Expand Down Expand Up @@ -899,11 +900,11 @@ class MmapInputFile : public InputFile {
MmapInputFile& operator=(const MmapInputFile&) = delete;
~MmapInputFile() override;

bool TryOpen(absl::string_view filename,
bool TryOpen(std::string_view filename,
std::unique_ptr<InputFile>& file) override {
return DoTryOpen(filename, file);
}
static bool DoTryOpen(absl::string_view filename,
static bool DoTryOpen(std::string_view filename,
std::unique_ptr<InputFile>& file);
};

Expand All @@ -923,7 +924,7 @@ class FileDescriptor {
int fd_;
};

bool MmapInputFile::DoTryOpen(absl::string_view filename,
bool MmapInputFile::DoTryOpen(std::string_view filename,
std::unique_ptr<InputFile>& file) {
std::string str(filename);
FileDescriptor fd(open(str.c_str(), O_RDONLY));
Expand Down Expand Up @@ -987,11 +988,11 @@ class Win32MMapInputFile : public InputFile {
Win32MMapInputFile& operator=(const Win32MMapInputFile&) = delete;
~Win32MMapInputFile() override;

bool TryOpen(absl::string_view filename,
bool TryOpen(std::string_view filename,
std::unique_ptr<InputFile>& file) override {
return DoTryOpen(filename, file);
}
static bool DoTryOpen(absl::string_view filename,
static bool DoTryOpen(std::string_view filename,
std::unique_ptr<InputFile>& file);
};

Expand All @@ -1017,7 +1018,7 @@ Win32MMapInputFile::Win32MMapInputFile(string_view filename, string_view data)
data_ = data;
}

bool Win32MMapInputFile::DoTryOpen(absl::string_view filename,
bool Win32MMapInputFile::DoTryOpen(std::string_view filename,
std::unique_ptr<InputFile>& file) {
std::string str(filename);
Win32Handle fd(::CreateFileA(str.c_str(), FILE_GENERIC_READ, FILE_SHARE_READ,
Expand Down Expand Up @@ -1221,8 +1222,8 @@ void RangeSink::AddFileRangeForVMAddr(const char* analyzer,
}

void RangeSink::AddFileRangeForFileRange(const char* analyzer,
absl::string_view from_file_range,
absl::string_view file_range) {
std::string_view from_file_range,
std::string_view file_range) {
uint64_t file_offset = file_range.data() - file_->data().data();
uint64_t from_file_offset = from_file_range.data() - file_->data().data();
bool verbose = IsVerboseForFileRange(file_offset, file_range.size());
Expand Down Expand Up @@ -1366,7 +1367,7 @@ uint64_t RangeSink::TranslateFileToVM(const char* ptr) {
return translated;
}

absl::string_view RangeSink::TranslateVMToFile(uint64_t address) {
std::string_view RangeSink::TranslateVMToFile(uint64_t address) {
assert(translator_);
uint64_t translated;
if (!translator_->vm_map.Translate(address, &translated) ||
Expand All @@ -1377,7 +1378,7 @@ absl::string_view RangeSink::TranslateVMToFile(uint64_t address) {
return file_->data().substr(translated);
}

absl::string_view RangeSink::ZlibDecompress(absl::string_view data,
std::string_view RangeSink::ZlibDecompress(std::string_view data,
uint64_t uncompressed_size) {
if (!arena_) {
THROW("This range sink isn't prepared to zlib decompress.");
Expand All @@ -1390,7 +1391,7 @@ absl::string_view RangeSink::ZlibDecompress(absl::string_view data,
"warning: ignoring compressed debug data, implausible uncompressed "
"size (compressed: %zu, uncompressed: %" PRIu64 ")\n",
data.size(), uncompressed_size);
return absl::string_view();
return std::string_view();
}
unsigned char* dbuf =
arena_->google::protobuf::Arena::CreateArray<unsigned char>(
Expand Down
54 changes: 27 additions & 27 deletions src/bloaty.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include <memory>
#include <set>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>

#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "capstone/capstone.h"

Expand Down Expand Up @@ -69,21 +69,21 @@ enum class DataSource {

class InputFile {
public:
InputFile(absl::string_view filename) : filename_(filename) {}
InputFile(std::string_view filename) : filename_(filename) {}
InputFile(const InputFile&) = delete;
InputFile& operator=(const InputFile&) = delete;
virtual bool TryOpen(absl::string_view filename,
virtual bool TryOpen(std::string_view filename,
std::unique_ptr<InputFile>& file) = 0;
virtual ~InputFile() {}

const std::string& filename() const { return filename_; }
absl::string_view data() const { return data_; }
std::string_view data() const { return data_; }

private:
const std::string filename_;

protected:
absl::string_view data_;
std::string_view data_;
};

class InputFileFactory {
Expand Down Expand Up @@ -129,34 +129,34 @@ class RangeSink {
// If vmsize or filesize is zero, this mapping is presumed not to exist in
// that domain. For example, .bss mappings don't exist in the file, and
// .debug_* mappings don't exist in memory.
void AddRange(const char *analyzer, absl::string_view name, uint64_t vmaddr,
void AddRange(const char *analyzer, std::string_view name, uint64_t vmaddr,
uint64_t vmsize, uint64_t fileoff, uint64_t filesize);

void AddRange(const char *analyzer, absl::string_view name, uint64_t vmaddr,
uint64_t vmsize, absl::string_view file_range) {
void AddRange(const char *analyzer, std::string_view name, uint64_t vmaddr,
uint64_t vmsize, std::string_view file_range) {
AddRange(analyzer, name, vmaddr, vmsize,
file_range.data() - file_->data().data(), file_range.size());
}

void AddFileRange(const char* analyzer, absl::string_view name,
void AddFileRange(const char* analyzer, std::string_view name,
uint64_t fileoff, uint64_t filesize);

// Like AddFileRange(), but the label is whatever label was previously
// assigned to VM address |label_from_vmaddr|. If no existing label is
// assigned to |label_from_vmaddr|, this function does nothing.
void AddFileRangeForVMAddr(const char* analyzer, uint64_t label_from_vmaddr,
absl::string_view file_range);
std::string_view file_range);
void AddVMRangeForVMAddr(const char* analyzer, uint64_t label_from_vmaddr,
uint64_t addr, uint64_t size);

// Applies this label from |from_file_range| to |file_range|, but only if the
// entire |from_file_range| has a single label. If not, this does nothing.
void AddFileRangeForFileRange(const char* analyzer,
absl::string_view from_file_range,
absl::string_view file_range);
std::string_view from_file_range,
std::string_view file_range);

void AddFileRange(const char* analyzer, absl::string_view name,
absl::string_view file_range) {
void AddFileRange(const char* analyzer, std::string_view name,
std::string_view file_range) {
// When separate debug files are being used, the DWARF analyzer will try to
// add sections of the debug file. We want to prevent this because we only
// want to profile the main file (not the debug file), so we filter these
Expand Down Expand Up @@ -202,21 +202,21 @@ class RangeSink {
// Translates the given pointer (which must be within the range of
// input_file().data()) to a VM address.
uint64_t TranslateFileToVM(const char* ptr);
absl::string_view TranslateVMToFile(uint64_t address);
std::string_view TranslateVMToFile(uint64_t address);
const DualMap* Translator() { return translator_; }


// Decompresses zlib-formatted data and returns the decompressed data.
// Since the decompressed data is not actually part of the file, any
// Add*Range() calls to this region will be no-ops.
absl::string_view ZlibDecompress(absl::string_view contents,
std::string_view ZlibDecompress(std::string_view contents,
uint64_t uncompressed_size);

static constexpr uint64_t kUnknownSize = RangeMap::kUnknownSize;

private:
bool FileContainsPointer(const void* ptr) const {
absl::string_view file_data = file_->data();
std::string_view file_data = file_->data();
return ptr >= file_data.data() && ptr < file_data.data() + file_data.size();
}

Expand Down Expand Up @@ -246,15 +246,15 @@ class NameMunger {
// Adds a regex that will be applied to all names. All regexes will be
// applied in sequence.
void AddRegex(const std::string& regex, const std::string& replacement);
std::string Munge(absl::string_view name) const;
std::string Munge(std::string_view name) const;

bool IsEmpty() const { return regexes_.empty(); }

private:
std::vector<std::pair<std::unique_ptr<ReImpl>, std::string>> regexes_;
};

typedef std::map<absl::string_view, std::pair<uint64_t, uint64_t>> SymbolTable;
typedef std::map<std::string_view, std::pair<uint64_t, uint64_t>> SymbolTable;

// Represents an object/executable file in a format like ELF, Mach-O, PE, etc.
// To support a new file type, implement this interface.
Expand All @@ -271,7 +271,7 @@ class ObjectFile {
// given here, otherwise it is |this|.
virtual void ProcessFile(const std::vector<RangeSink*>& sinks) const = 0;

virtual bool GetDisassemblyInfo(absl::string_view symbol,
virtual bool GetDisassemblyInfo(std::string_view symbol,
DataSource symbol_source,
DisassemblyInfo* info) const = 0;

Expand Down Expand Up @@ -307,12 +307,12 @@ inline void ReadDWARFCompileUnits(const dwarf::File& file, const DualMap& map,
}
void ReadDWARFInlines(const dwarf::File& file, RangeSink* sink,
bool include_line);
void ReadEhFrame(absl::string_view contents, RangeSink* sink);
void ReadEhFrameHdr(absl::string_view contents, RangeSink* sink);
void ReadEhFrame(std::string_view contents, RangeSink* sink);
void ReadEhFrameHdr(std::string_view contents, RangeSink* sink);

// Demangle C++ symbols according to the Itanium ABI. The |source| argument
// controls what demangling mode we are using.
std::string ItaniumDemangle(absl::string_view symbol, DataSource source);
std::string ItaniumDemangle(std::string_view symbol, DataSource source);


// DualMap /////////////////////////////////////////////////////////////////////
Expand All @@ -325,7 +325,7 @@ struct DualMap {
};

struct DisassemblyInfo {
absl::string_view text;
std::string_view text;
DualMap symbol_map;
cs_arch arch;
cs_mode mode;
Expand Down Expand Up @@ -398,17 +398,17 @@ struct RollupOutput {
RollupOutput(const RollupOutput&) = delete;
RollupOutput& operator=(const RollupOutput&) = delete;

void AddDataSourceName(absl::string_view name) {
void AddDataSourceName(std::string_view name) {
source_names_.emplace_back(std::string(name));
}

const std::vector<std::string>& source_names() const { return source_names_; }
void Print(const OutputOptions& options, std::ostream* out);
void SetDisassembly(absl::string_view disassembly) {
void SetDisassembly(std::string_view disassembly) {
disassembly_ = std::string(disassembly);
}

absl::string_view GetDisassembly() { return disassembly_; }
std::string_view GetDisassembly() { return disassembly_; }

// For debugging.
const RollupRow& toplevel_row() const { return toplevel_row_; }
Expand Down
4 changes: 2 additions & 2 deletions src/disassemble.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
// limitations under the License.

#include <string>
#include <string_view>

#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "bloaty.h"
#include "capstone/capstone.h"
#include "re.h"
#include "util.h"

using absl::string_view;
using std::string_view;

namespace bloaty {

Expand Down
8 changes: 4 additions & 4 deletions src/dwarf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#include <limits>
#include <memory>
#include <stack>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include "absl/base/attributes.h"
#include "absl/base/macros.h"
#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "absl/types/optional.h"
#include "bloaty.h"
Expand All @@ -39,7 +39,7 @@
#include "dwarf/line_info.h"

using namespace dwarf2reader;
using absl::string_view;
using std::string_view;

namespace bloaty {

Expand Down Expand Up @@ -446,7 +446,7 @@ void AddDIE(const dwarf::CU& cu, const GeneralDIE& die,
if (die.location_uint64) {
uint64_t location = *die.location_uint64;;
if (location < cu.dwarf().debug_loc.size()) {
absl::string_view loc_range = c 3D11 u.dwarf().debug_loc.substr(location);
std::string_view loc_range = cu.dwarf().debug_loc.substr(location);
loc_range = GetLocationListRange(cu.unit_sizes(), loc_range);
sink->AddFileRange("dwarf_locrange", cu.unit_name(), loc_range);
} else if (verbose_level > 0) {
Expand Down Expand Up @@ -526,7 +526,7 @@ void AddDIE(const dwarf::CU& cu, const GeneralDIE& die,

if (ranges_offset != UINT64_MAX) {
if (ranges_offset < cu.dwarf().debug_ranges.size()) {
absl::string_view data = cu.dwarf().debug_ranges.substr(ranges_offset);
std::string_view data = cu.dwarf().debug_ranges.substr(ranges_offset);
const char* start = data.data();
ReadRangeList(cu, low_pc, cu.unit_name(), sink, &data);
string_view all(start, data.data() - start);
Expand Down
2 changes: 1 addition & 1 deletion src/dwarf/attr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "dwarf_constants.h"
#include "util.h"

using string_view = absl::string_view;
using string_view = std::string_view;
using namespace dwarf2reader;

namespace bloaty {
Expand Down
Loading
Loading
0