Skip to content

Commit

Permalink
Enable clang-format AllowShortBlocksOnASingleLine
Browse files Browse the repository at this point in the history
This looks much cleaner and readable IMHO. There is also an "Always" option for
this, but its output feels less readable to me.
  • Loading branch information
fhanau committed Sep 19, 2024
1 parent 63650fe commit fa2c488
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 172 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ IncludeCategories:

AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortBlocksOnASingleLine: Empty

IndentWidth: 2
IndentCaseBlocks: false
Expand Down
3 changes: 1 addition & 2 deletions src/workerd/api/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ class Blob: public jsg::Object {
KJ_CASE_ONEOF(b, jsg::Ref<Blob>) {
visitor.visit(b);
}
KJ_CASE_ONEOF(b, kj::Array<kj::byte>) {
}
KJ_CASE_ONEOF(b, kj::Array<kj::byte>) {}
}
}

Expand Down
12 changes: 4 additions & 8 deletions src/workerd/api/streams/internal.c++
Original file line number Diff line number Diff line change
Expand Up @@ -2483,8 +2483,7 @@ size_t WritableStreamInternalController::jsgGetMemorySelfSize() const {
}
void WritableStreamInternalController::jsgGetMemoryInfo(jsg::MemoryTracker& tracker) const {
KJ_SWITCH_ONEOF(state) {
KJ_CASE_ONEOF(closed, StreamStates::Closed) {
}
KJ_CASE_ONEOF(closed, StreamStates::Closed) {}
KJ_CASE_ONEOF(errored, StreamStates::Errored) {
tracker.trackField("error", errored);
}
Expand Down Expand Up @@ -2528,8 +2527,7 @@ size_t ReadableStreamInternalController::jsgGetMemorySelfSize() const {

void ReadableStreamInternalController::jsgGetMemoryInfo(jsg::MemoryTracker& tracker) const {
KJ_SWITCH_ONEOF(state) {
KJ_CASE_ONEOF(closed, StreamStates::Closed) {
}
KJ_CASE_ONEOF(closed, StreamStates::Closed) {}
KJ_CASE_ONEOF(error, StreamStates::Errored) {
tracker.trackField("error", error);
}
Expand All @@ -2542,10 +2540,8 @@ void ReadableStreamInternalController::jsgGetMemoryInfo(jsg::MemoryTracker& trac
}
}
KJ_SWITCH_ONEOF(readState) {
KJ_CASE_ONEOF(unlocked, Unlocked) {
}
KJ_CASE_ONEOF(locked, Locked) {
}
KJ_CASE_ONEOF(unlocked, Unlocked) {}
KJ_CASE_ONEOF(locked, Locked) {}
KJ_CASE_ONEOF(pipeLocked, PipeLocked) {
tracker.trackField("pipeLocked", pipeLocked);
}
Expand Down
24 changes: 8 additions & 16 deletions src/workerd/api/streams/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,8 @@ class ConsumerImpl final {

void cancel(jsg::Lock& js, jsg::Optional<v8::Local<v8::Value>> maybeReason) {
KJ_SWITCH_ONEOF(state) {
KJ_CASE_ONEOF(closed, Closed) {
}
KJ_CASE_ONEOF(errored, Errored) {
}
KJ_CASE_ONEOF(closed, Closed) {}
KJ_CASE_ONEOF(errored, Errored) {}
KJ_CASE_ONEOF(ready, Ready) {
for (auto& request: ready.readRequests) {
request.resolveAsDone(js);
Expand Down Expand Up @@ -505,10 +503,8 @@ class ConsumerImpl final {

void cancelPendingReads(jsg::Lock& js, jsg::JsValue reason) {
KJ_SWITCH_ONEOF(state) {
KJ_CASE_ONEOF(closed, Closed) {
}
KJ_CASE_ONEOF(errored, Errored) {
}
KJ_CASE_ONEOF(closed, Closed) {}
KJ_CASE_ONEOF(errored, Errored) {}
KJ_CASE_ONEOF(ready, Ready) {
for (auto& request: ready.readRequests) {
request.resolver.reject(js, reason);
Expand All @@ -520,8 +516,7 @@ class ConsumerImpl final {

void visitForGc(jsg::GcVisitor& visitor) {
KJ_SWITCH_ONEOF(state) {
KJ_CASE_ONEOF(closed, Closed) {
}
KJ_CASE_ONEOF(closed, Closed) {}
KJ_CASE_ONEOF(errored, Errored) {
// Technically we shouldn't really have to gc visit the stored error here but there
// should not be any harm in doing so.
Expand Down Expand Up @@ -1016,10 +1011,8 @@ size_t QueueImpl<Self>::jsgGetMemorySelfSize() const {
template <typename Self>
void QueueImpl<Self>::jsgGetMemoryInfo(jsg::MemoryTracker& tracker) const {
KJ_SWITCH_ONEOF(state) {
KJ_CASE_ONEOF(ready, Ready) {
}
KJ_CASE_ONEOF(closed, Closed) {
}
KJ_CASE_ONEOF(ready, Ready) {}
KJ_CASE_ONEOF(closed, Closed) {}
KJ_CASE_ONEOF(errored, Errored) {
tracker.trackField("error", errored);
}
Expand All @@ -1039,8 +1032,7 @@ size_t ConsumerImpl<Self>::jsgGetMemorySelfSize() const {
template <typename Self>
void ConsumerImpl<Self>::jsgGetMemoryInfo(jsg::MemoryTracker& tracker) const {
KJ_SWITCH_ONEOF(state) {
KJ_CASE_ONEOF(close, Closed) {
}
KJ_CASE_ONEOF(close, Closed) {}
KJ_CASE_ONEOF(error, Errored) {
tracker.trackField("error", error);
}
Expand Down
33 changes: 11 additions & 22 deletions src/workerd/api/streams/standard-test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ KJ_TEST("ReadableStream read all text (value readable)") {
c->close(js);
return js.resolvedPromise();
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {}
}
KJ_UNREACHABLE;
}
Expand Down Expand Up @@ -120,8 +119,7 @@ KJ_TEST("ReadableStream read all text, rs ref held (value readable)") {
c->close(js);
return js.resolvedPromise();
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {}
}
KJ_UNREACHABLE;
}
Expand Down Expand Up @@ -175,8 +173,7 @@ KJ_TEST("ReadableStream read all text (byte readable)") {
c->close(js);
return js.resolvedPromise();
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableStreamDefaultController>) {
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableStreamDefaultController>) {}
}
KJ_UNREACHABLE;
}
Expand Down Expand Up @@ -233,8 +230,7 @@ KJ_TEST("ReadableStream read all bytes (value readable)") {
c->close(js);
return js.resolvedPromise();
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {}
}
KJ_UNREACHABLE;
}
Expand Down Expand Up @@ -292,8 +288,7 @@ KJ_TEST("ReadableStream read all bytes (byte readable)") {
c->close(js);
return js.resolvedPromise();
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableStreamDefaultController>) {
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableStreamDefaultController>) {}
}
KJ_UNREACHABLE;
}
Expand Down Expand Up @@ -356,8 +351,7 @@ KJ_TEST("ReadableStream read all bytes (value readable, more reads)") {

return js.resolvedPromise();
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {}
}
KJ_UNREACHABLE;
}
Expand Down Expand Up @@ -421,8 +415,7 @@ KJ_TEST("ReadableStream read all bytes (byte readable, more reads)") {

return js.resolvedPromise();
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableStreamDefaultController>) {
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableStreamDefaultController>) {}
}
KJ_UNREACHABLE;
}
Expand Down Expand Up @@ -489,8 +482,7 @@ KJ_TEST("ReadableStream read all bytes (byte readable, large data)") {

return js.resolvedPromise();
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableStreamDefaultController>) {
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableStreamDefaultController>) {}
}
KJ_UNREACHABLE;
}
Expand Down Expand Up @@ -554,8 +546,7 @@ KJ_TEST("ReadableStream read all bytes (value readable, wrong type)") {
checked++;
return js.resolvedPromise();
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {}
}
KJ_UNREACHABLE;
},
Expand Down Expand Up @@ -616,8 +607,7 @@ KJ_TEST("ReadableStream read all bytes (value readable, to many bytes)") {
checked++;
return js.resolvedPromise();
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableByteStreamController>) {}
}
KJ_UNREACHABLE;
}
Expand Down Expand Up @@ -673,8 +663,7 @@ KJ_TEST("ReadableStream read all bytes (byte readable, to many bytes)") {
checked++;
return js.resolvedPromise();
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableStreamDefaultController>) {
}
KJ_CASE_ONEOF(c, jsg::Ref<ReadableStreamDefaultController>) {}
}
KJ_UNREACHABLE;
}
Expand Down
Loading

0 comments on commit fa2c488

Please sign in to comment.