Hash :
00d6796a
Author :
Date :
2016-07-28T16:20:21
Replace std::set with vector for signal receivers. This should make insertion much faster, which will improve the speed of many BindBuffer calls. BUG=angleproject:1458 Change-Id: I3f7ebc02cc481257be8b84773506b9ac9e3be677 Reviewed-on: https://chromium-review.googlesource.com/364221 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// signal_utils:
// Helper classes for tracking dependent state changes between objects.
// These changes are signaled to the dependent class via channels.
#include "libANGLE/signal_utils.h"
#include <algorithm>
#include "common/debug.h"
namespace angle
{
BroadcastChannel::BroadcastChannel()
{
}
BroadcastChannel::~BroadcastChannel()
{
reset();
}
void BroadcastChannel::addReceiver(ChannelBinding *receiver)
{
ASSERT(std::find(mReceivers.begin(), mReceivers.end(), receiver) == mReceivers.end());
mReceivers.push_back(receiver);
}
void BroadcastChannel::removeReceiver(ChannelBinding *receiver)
{
auto iter = std::find(mReceivers.begin(), mReceivers.end(), receiver);
ASSERT(iter != mReceivers.end());
mReceivers.erase(iter);
}
void BroadcastChannel::signal() const
{
if (mReceivers.empty())
return;
for (const auto *receiver : mReceivers)
{
receiver->signal();
}
}
void BroadcastChannel::reset()
{
for (auto receiver : mReceivers)
{
receiver->onChannelClosed();
}
mReceivers.clear();
}
ChannelBinding::ChannelBinding(SignalReceiver *receiver, SignalToken token)
: mChannel(nullptr), mReceiver(receiver), mToken(token)
{
ASSERT(receiver);
}
ChannelBinding::~ChannelBinding()
{
reset();
}
void ChannelBinding::bind(BroadcastChannel *channel)
{
ASSERT(mReceiver);
if (mChannel)
{
mChannel->removeReceiver(this);
}
mChannel = channel;
if (mChannel)
{
mChannel->addReceiver(this);
}
}
void ChannelBinding::reset()
{
bind(nullptr);
}
void ChannelBinding::signal() const
{
mReceiver->signal(mToken);
}
void ChannelBinding::onChannelClosed()
{
mChannel = nullptr;
}
} // namespace angle