Skip to content

Commit 0cccec0

Browse files
committed
Reuse standard OK payload objects.
Use the "flyweight pattern" to reduce allocations of common OK payloads.
1 parent 8237bb6 commit 0cccec0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/MySqlConnector/Protocol/Payloads/OkPayload.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ public static OkPayload Create(PayloadData payload, bool deprecateEof)
6868
// ignore human-readable string in both cases
6969
}
7070

71+
if (affectedRowCount == 0 && lastInsertId == 0 && warningCount == 0 && newSchema == null)
72+
{
73+
if (serverStatus == ServerStatus.AutoCommit)
74+
return s_autoCommitOk;
75+
if (serverStatus == (ServerStatus.AutoCommit | ServerStatus.SessionStateChanged))
76+
return s_autoCommitSessionStateChangedOk;
77+
}
78+
7179
return new OkPayload(affectedRowCount, lastInsertId, serverStatus, warningCount, newSchema);
7280
}
7381

@@ -79,5 +87,8 @@ private OkPayload(int affectedRowCount, ulong lastInsertId, ServerStatus serverS
7987
WarningCount = warningCount;
8088
NewSchema = newSchema;
8189
}
90+
91+
static readonly OkPayload s_autoCommitOk = new OkPayload(0, 0, ServerStatus.AutoCommit, 0, null);
92+
static readonly OkPayload s_autoCommitSessionStateChangedOk = new OkPayload(0, 0, ServerStatus.AutoCommit | ServerStatus.SessionStateChanged, 0, null);
8293
}
8394
}

0 commit comments

Comments
 (0)