Use fewer pointers refactor: eliminate some pointers in DrivenEngine

This commit is contained in:
2026-02-21 18:47:54 -05:00
parent 0531f50056
commit 48b7bf37da
3 changed files with 11 additions and 36 deletions

View File

@@ -110,22 +110,20 @@ static DrivenEngine *make_engine(std::string_view kind) {
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Channel::Channel(DrivenEngine *de, int chid, int port, const eng::string &target, bool stop) {
Channel::Channel(int chid, int port, const eng::string &target, bool stop) {
chid_ = chid;
port_ = port;
closed_ = false;
target_ = target;
stop_driver_ = stop;
sb_in_ = eng::make_shared<StreamBuffer>();
sb_out_ = eng::make_shared<StreamBuffer>();
}
std::string_view Channel::peek_outgoing() const {
return sb_out_->view();
return sb_out_.view();
}
void Channel::sent_outgoing(int nbytes) {
sb_out_->read_bytes(nbytes);
sb_out_.read_bytes(nbytes);
}
//////////////////////////////////////////////////////////////////////////////
@@ -148,7 +146,7 @@ double DrivenEngine::get_clock() {
SharedChannel DrivenEngine::new_outgoing_channel(const eng::string &target) {
int chid = find_unused_chid();
new_outgoing_.push_back(chid);
SharedChannel result = eng::make_shared<Channel>(this, chid, 0, target, stop_driver_);
SharedChannel result = eng::make_shared<Channel>(chid, 0, target, stop_driver_);
channels_[chid] = result;
return result;
}
@@ -441,7 +439,7 @@ void DrivenEngine::drv_recv_incoming(uint32_t chid, uint32_t nbytes, const char
if (nbytes > 0) {
std::string_view sbytes(bytes, nbytes);
Channel *ch = get_chid(chid);
ch->sb_in_->write_bytes(sbytes);
ch->sb_in_.write_bytes(sbytes);
}
}
@@ -454,7 +452,7 @@ void DrivenEngine::drv_notify_close(uint32_t chid, uint32_t len, const char *dat
uint32_t DrivenEngine::drv_notify_accept(uint32_t port) {
int chid = find_unused_chid();
channels_[chid] = eng::make_shared<Channel>(this, chid, port, "", stop_driver_);
channels_[chid] = eng::make_shared<Channel>(chid, port, "", stop_driver_);
accepted_channels_.push_back(channels_[chid]);
return chid;
}

View File

@@ -65,8 +65,8 @@ class Channel : public eng::opnew {
public:
// Get the buffers associated with this channel.
//
StreamBuffer *out() { return sb_out_.get(); }
StreamBuffer *in() { return sb_in_.get(); }
StreamBuffer *out() { return &sb_out_; }
StreamBuffer *in() { return &sb_in_; }
// The channel ID. These are reused.
//
@@ -96,7 +96,7 @@ public:
// Channels are referenced by shared_ptr. You can
// release your shared_ptr at any time.
//
Channel(DrivenEngine *de, int chid, int port, const eng::string &target, bool stop);
Channel(int chid, int port, const eng::string &target, bool stop);
~Channel() {};
private:
@@ -110,8 +110,8 @@ private:
int chid_;
// These are the in/out buffers presented to the user.
std::shared_ptr<StreamBuffer> sb_in_;
std::shared_ptr<StreamBuffer> sb_out_;
StreamBuffer sb_in_;
StreamBuffer sb_out_;
int port_;
bool closed_;