Skip to content

Commit

Permalink
Replace uses of kj::str() with kj::String(), other StringPtr cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Oct 10, 2024
1 parent 20544a0 commit bc19cc7
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 194 deletions.
2 changes: 1 addition & 1 deletion src/workerd/api/actor-state.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ jsg::JsValue deserializeV8Value(
// include the key (to help find the data in the database if it hasn't been deleted), the
// length of the value, and the first three bytes of the value (which is just the v8-internal
// version header and the tag that indicates the type of the value, but not its contents).
kj::String actorId = getCurrentActorId().orDefault([]() { return kj::str(); });
kj::String actorId = getCurrentActorId().orDefault([]() { return kj::String(); });
KJ_FAIL_ASSERT("actor storage deserialization failed", "failed to deserialize stored value",
actorId, exception.getHandle(js), key, buf.size(),
buf.slice(0, std::min(static_cast<size_t>(3), buf.size())));
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/crypto/impl.c++
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ kj::String errorsToString(
return e;
}
KJ_CASE_ONEOF(e, OpensslUntranslatedError) {
return kj::StringPtr(e.reasonName);
return e.reasonName;
}
}
KJ_UNREACHABLE;
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/node/util.c++
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ kj::String MIMEParams::toString() {
KJ_IF_SOME(inner, mimeType) {
return inner.paramsToString();
}
return kj::str();
return kj::String();
}

jsg::Ref<MIMEParams::EntryIterator> MIMEParams::entries(jsg::Lock&) {
Expand Down
4 changes: 2 additions & 2 deletions src/workerd/api/r2-multipart.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class R2MultipartUpload: public jsg::Object {
bucket(kj::mv(bucket)) {}

kj::StringPtr getKey() const {
return kj::StringPtr(key);
return key;
}
kj::StringPtr getUploadId() const {
return kj::StringPtr(uploadId);
return uploadId;
}

jsg::Promise<UploadedPart> uploadPart(jsg::Lock& js,
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/url-standard.c++
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ jsg::UrlSearchParams initFromSearch(kj::Maybe<kj::ArrayPtr<const char>>& maybeQu
} // namespace

jsg::Ref<URLSearchParams> URLSearchParams::constructor(jsg::Optional<Initializer> init) {
return jsg::alloc<URLSearchParams>(kj::mv(init).orDefault(kj::str()));
return jsg::alloc<URLSearchParams>(kj::mv(init).orDefault(kj::String()));
}

URLSearchParams::URLSearchParams(Initializer initializer): inner(initSearchParams(initializer)) {}
Expand Down
38 changes: 19 additions & 19 deletions src/workerd/api/urlpattern.c++
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ kj::Maybe<URLPattern::URLPatternComponentResult> execRegex(jsg::Lock& js,
auto value = array.get(js, index);
fields.add(Groups::Field{
.name = kj::str(nameList[index - 1]),
.value = value.isUndefined() ? kj::str() : kj::str(value),
.value = value.isUndefined() ? kj::String() : kj::str(value),
});
index++;
}
Expand Down Expand Up @@ -182,14 +182,14 @@ kj::Maybe<URLPattern::URLPatternResult> URLPattern::exec(
auto input = kj::mv(maybeInput).orDefault(URLPattern::URLPatternInit());
kj::Vector<URLPattern::URLPatternInput> inputs(2);

kj::String protocol = kj::str();
kj::String username = kj::str();
kj::String password = kj::str();
kj::String hostname = kj::str();
kj::String port = kj::str();
kj::String pathname = kj::str();
kj::String search = kj::str();
kj::String hash = kj::str();
kj::String protocol = nullptr;
kj::String username = nullptr;
kj::String password = nullptr;
kj::String hostname = nullptr;
kj::String port = nullptr;
kj::String pathname = nullptr;
kj::String search = nullptr;
kj::String hash = nullptr;

KJ_SWITCH_ONEOF(input) {
KJ_CASE_ONEOF(string, kj::String) {
Expand All @@ -203,8 +203,8 @@ kj::Maybe<URLPattern::URLPatternResult> URLPattern::exec(
hostname = kj::str(url.getHostname());
port = kj::str(url.getPort());
pathname = kj::str(url.getPathname());
search = url.getSearch().size() > 0 ? kj::str(url.getSearch().slice(1)) : kj::str();
hash = url.getHash().size() > 0 ? kj::str(url.getHash().slice(1)) : kj::str();
search = url.getSearch().size() > 0 ? kj::str(url.getSearch().slice(1)) : kj::String();
hash = url.getHash().size() > 0 ? kj::str(url.getHash().slice(1)) : kj::String();
} else {
return kj::none;
}
Expand Down Expand Up @@ -248,14 +248,14 @@ kj::Maybe<URLPattern::URLPatternResult> URLPattern::exec(
JSG_FAIL_REQUIRE(TypeError, kj::mv(err));
}
KJ_CASE_ONEOF(init, jsg::UrlPattern::Init) {
protocol = kj::mv(init.protocol).orDefault(kj::str());
username = kj::mv(init.username).orDefault(kj::str());
password = kj::mv(init.password).orDefault(kj::str());
hostname = kj::mv(init.hostname).orDefault(kj::str());
port = kj::mv(init.port).orDefault(kj::str());
pathname = kj::mv(init.pathname).orDefault(kj::str());
search = kj::mv(init.search).orDefault(kj::str());
hash = kj::mv(init.hash).orDefault(kj::str());
protocol = kj::mv(init.protocol).orDefault(kj::String());
username = kj::mv(init.username).orDefault(kj::String());
password = kj::mv(init.password).orDefault(kj::String());
hostname = kj::mv(init.hostname).orDefault(kj::String());
port = kj::mv(init.port).orDefault(kj::String());
pathname = kj::mv(init.pathname).orDefault(kj::String());
search = kj::mv(init.search).orDefault(kj::String());
hash = kj::mv(init.hash).orDefault(kj::String());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/web-socket.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ kj::Array<kj::StringPtr> WebSocket::Accepted::WrappedWebSocket::getHibernatableT
// We have the array already, let's copy it and return.
auto cpy = kj::heapArray<kj::StringPtr>(arr.size());
for (auto& i: kj::indices(arr)) {
cpy[i] = kj::StringPtr(arr[i]);
cpy[i] = arr[i].asPtr();
}
return cpy;
}
Expand Down
Loading

0 comments on commit bc19cc7

Please sign in to comment.