Skip to content

Commit 6d19e7c

Browse files
committed
SVNetwork: Avoid unneeded new / delete operations
The class variable mutex_send_ does not require an indirection by using a pointer. Signed-off-by: Stefan Weil <[email protected]>
1 parent 83588bc commit 6d19e7c

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

viewer/svutil.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,19 @@ void SVSemaphore::Wait() {
208208

209209
// Place a message in the message buffer (and flush it).
210210
void SVNetwork::Send(const char* msg) {
211-
mutex_send_->Lock();
211+
mutex_send_.Lock();
212212
msg_buffer_out_.append(msg);
213-
mutex_send_->Unlock();
213+
mutex_send_.Unlock();
214214
}
215215

216216
// Send the whole buffer.
217217
void SVNetwork::Flush() {
218-
mutex_send_->Lock();
218+
mutex_send_.Lock();
219219
while (!msg_buffer_out_.empty()) {
220220
int i = send(stream_, msg_buffer_out_.c_str(), msg_buffer_out_.length(), 0);
221221
msg_buffer_out_.erase(0, i);
222222
}
223-
mutex_send_->Unlock();
223+
mutex_send_.Unlock();
224224
}
225225

226226
// Receive a message from the server.
@@ -387,7 +387,6 @@ static int GetAddrInfo(const char* hostname, int port,
387387

388388
// Set up a connection to a ScrollView on hostname:port.
389389
SVNetwork::SVNetwork(const char* hostname, int port) {
390-
mutex_send_ = new SVMutex();
391390
msg_buffer_in_ = new char[kMaxMsgSize + 1];
392391
msg_buffer_in_[0] = '\0';
393392

@@ -448,7 +447,6 @@ SVNetwork::SVNetwork(const char* hostname, int port) {
448447

449448
SVNetwork::~SVNetwork() {
450449
delete[] msg_buffer_in_;
451-
delete mutex_send_;
452450
}
453451

454452
#endif // GRAPHICS_DISABLED

viewer/svutil.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class SVNetwork {
141141

142142
private:
143143
/// The mutex for access to Send() and Flush().
144-
SVMutex* mutex_send_;
144+
SVMutex mutex_send_;
145145
/// The actual stream_ to the server.
146146
int stream_;
147147
/// Stores the last received message-chunk from the server.

0 commit comments

Comments
 (0)