Commit 1b468272 authored by Kenton Varda's avatar Kenton Varda

Misc tweaks.

parent c247947b
......@@ -525,7 +525,10 @@ public:
inline constexpr ArrayPtr(T* ptr, size_t size): ptr(ptr), size_(size) {}
inline constexpr ArrayPtr(T* begin, T* end): ptr(begin), size_(end - begin) {}
inline operator ArrayPtr<const T>() {
inline operator ArrayPtr<const T>() const {
return ArrayPtr<const T>(ptr, size_);
}
inline ArrayPtr<const T> asConst() const {
return ArrayPtr<const T>(ptr, size_);
}
......@@ -548,6 +551,15 @@ public:
inline bool operator==(decltype(nullptr)) { return size_ == 0; }
inline bool operator!=(decltype(nullptr)) { return size_ != 0; }
inline bool operator==(const ArrayPtr& other) const {
if (size_ != other.size_) return false;
for (size_t i = 0; i < size_; i++) {
if (ptr[i] != other[i]) return false;
}
return true;
}
inline bool operator!=(const ArrayPtr& other) const { return !(*this == other); }
private:
T* ptr;
size_t size_;
......
......@@ -49,7 +49,7 @@ String getStackSymbols(ArrayPtr<void* const> trace) {
}
exe[n] = '\0';
String lines[6];
String lines[8];
FILE* p = popen(str("addr2line -e ", exe, ' ', strArray(trace, " ")).cStr(), "r");
if (p == nullptr) {
......@@ -61,14 +61,15 @@ String getStackSymbols(ArrayPtr<void* const> trace) {
while (i < KJ_ARRAY_SIZE(lines) && fgets(line, sizeof(line), p) != nullptr) {
// Don't include exception-handling infrastructure in stack trace.
if (i == 0 &&
(strstr(line, "kj/exception.") != nullptr ||
(strstr(line, "kj/common.c++") != nullptr ||
strstr(line, "kj/exception.") != nullptr ||
strstr(line, "kj/debug.") != nullptr)) {
continue;
}
size_t len = strlen(line);
if (len > 0 && line[len-1] == '\n') line[len-1] = '\0';
lines[i++] = str("\n", line);
lines[i++] = str("\n", line, ": called here");
}
// Skip remaining input.
......
......@@ -45,6 +45,9 @@ public:
inline StringPtr(): content("", 1) {}
inline StringPtr(decltype(nullptr)): content("", 1) {}
inline StringPtr(const char* value): content(value, strlen(value) + 1) {}
inline StringPtr(const char* value, size_t size): content(value, size + 1) {
KJ_IREQUIRE(value[size] == '\0', "StringPtr must be NUL-terminated.");
}
inline StringPtr(const String& value);
inline operator ArrayPtr<const char>() const;
......@@ -65,8 +68,12 @@ public:
inline bool operator==(decltype(nullptr)) const { return content.size() <= 1; }
inline bool operator!=(decltype(nullptr)) const { return content.size() > 1; }
inline bool operator==(StringPtr other) const;
inline bool operator!=(StringPtr other) const { return !(*this == other); }
inline bool operator==(const StringPtr& other) const;
inline bool operator!=(const StringPtr& other) const { return !(*this == other); }
inline bool operator< (const StringPtr& other) const;
inline bool operator> (const StringPtr& other) const { return other < *this; }
inline bool operator<=(const StringPtr& other) const { return !(other < *this); }
inline bool operator>=(const StringPtr& other) const { return !(*this < other); }
inline StringPtr slice(size_t start) const;
inline ArrayPtr<const char> slice(size_t start, size_t end) const;
......@@ -121,8 +128,8 @@ public:
inline bool operator==(decltype(nullptr)) const { return content.size() <= 1; }
inline bool operator!=(decltype(nullptr)) const { return content.size() > 1; }
inline bool operator==(StringPtr other) const { return StringPtr(*this) == other; }
inline bool operator!=(StringPtr other) const { return !(*this == other); }
inline bool operator==(const StringPtr& other) const { return StringPtr(*this) == other; }
inline bool operator!=(const StringPtr& other) const { return !(*this == other); }
private:
Array<char> content;
......@@ -326,11 +333,18 @@ inline ArrayPtr<const char> StringPtr::asArray() const {
return content.slice(0, content.size() - 1);
}
inline bool StringPtr::operator==(StringPtr other) const {
inline bool StringPtr::operator==(const StringPtr& other) const {
return content.size() == other.content.size() &&
memcmp(content.begin(), other.content.begin(), content.size() - 1) == 0;
}
inline bool StringPtr::operator<(const StringPtr& other) const {
bool shorter = content.size() < other.content.size();
int cmp = memcmp(content.begin(), other.content.begin(),
shorter ? content.size() : other.content.size());
return cmp < 0 || (cmp == 0 && shorter);
}
inline StringPtr StringPtr::slice(size_t start) const {
return StringPtr(content.slice(start, content.size()));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment