Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: mojo/common/message_pump_mojo.h

Issue 1156923005: Cache vectors to avoid heap allocations on each message pump iteration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/common/message_pump_mojo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ 5 #ifndef MOJO_COMMON_MESSAGE_PUMP_MOJO_H_
6 #define MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ 6 #define MOJO_COMMON_MESSAGE_PUMP_MOJO_H_
7 7
8 #include <map> 8 #include <map>
9 #include <utility>
10 #include <vector>
9 11
10 #include "base/macros.h" 12 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_pump.h" 14 #include "base/message_loop/message_pump.h"
13 #include "base/observer_list.h" 15 #include "base/observer_list.h"
14 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
15 #include "base/time/time.h" 17 #include "base/time/time.h"
16 #include "mojo/public/cpp/system/core.h" 18 #include "mojo/public/cpp/system/core.h"
17 19
18 namespace mojo { 20 namespace mojo {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 Handler() : handler(NULL), wait_signals(MOJO_HANDLE_SIGNAL_NONE), id(0) {} 76 Handler() : handler(NULL), wait_signals(MOJO_HANDLE_SIGNAL_NONE), id(0) {}
75 77
76 MessagePumpMojoHandler* handler; 78 MessagePumpMojoHandler* handler;
77 MojoHandleSignals wait_signals; 79 MojoHandleSignals wait_signals;
78 base::TimeTicks deadline; 80 base::TimeTicks deadline;
79 // See description of |MessagePumpMojo::next_handler_id_| for details. 81 // See description of |MessagePumpMojo::next_handler_id_| for details.
80 int id; 82 int id;
81 }; 83 };
82 84
83 typedef std::map<Handle, Handler> HandleToHandler; 85 typedef std::map<Handle, Handler> HandleToHandler;
86 typedef std::vector<std::pair<Handle, Handler>> HandleToHandlerList;
84 87
85 // Implementation of Run(). 88 // Implementation of Run().
86 void DoRunLoop(RunState* run_state, Delegate* delegate); 89 void DoRunLoop(RunState* run_state, Delegate* delegate);
87 90
88 // Services the set of handles ready. If |block| is true this waits for a 91 // Services the set of handles ready. If |block| is true this waits for a
89 // handle to become ready, otherwise this does not block. Returns |true| if a 92 // handle to become ready, otherwise this does not block. Returns |true| if a
90 // handle has become ready, |false| otherwise. 93 // handle has become ready, |false| otherwise.
91 bool DoInternalWork(const RunState& run_state, bool block); 94 bool DoInternalWork(const RunState& run_state, bool block);
92 95
93 // Removes the given invalid handle. This is called if MojoWaitMany finds an 96 // Removes the given invalid handle. This is called if MojoWaitMany finds an
94 // invalid handle. 97 // invalid handle.
95 void RemoveInvalidHandle(const WaitState& wait_state, 98 void RemoveInvalidHandle(const WaitState& wait_state,
96 MojoResult result, 99 MojoResult result,
97 uint32_t result_index); 100 uint32_t result_index);
98 101
99 void SignalControlPipe(const RunState& run_state); 102 void SignalControlPipe(const RunState& run_state);
100 103
101 WaitState GetWaitState(const RunState& run_state) const; 104 void GetWaitState(const RunState& run_state, WaitState* wait_state) const;
102 105
103 // Returns the deadline for the call to MojoWaitMany(). 106 // Returns the deadline for the call to MojoWaitMany().
104 MojoDeadline GetDeadlineForWait(const RunState& run_state) const; 107 MojoDeadline GetDeadlineForWait(const RunState& run_state) const;
105 108
106 void WillSignalHandler(); 109 void WillSignalHandler();
107 void DidSignalHandler(); 110 void DidSignalHandler();
108 111
109 // If non-NULL we're running (inside Run()). Member is reference to value on 112 // If non-NULL we're running (inside Run()). Member is reference to value on
110 // stack. 113 // stack.
111 RunState* run_state_; 114 RunState* run_state_;
(...skipping 14 matching lines...) Expand all
126 129
127 ObserverList<Observer> observers_; 130 ObserverList<Observer> observers_;
128 131
129 DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo); 132 DISALLOW_COPY_AND_ASSIGN(MessagePumpMojo);
130 }; 133 };
131 134
132 } // namespace common 135 } // namespace common
133 } // namespace mojo 136 } // namespace mojo
134 137
135 #endif // MOJO_COMMON_MESSAGE_PUMP_MOJO_H_ 138 #endif // MOJO_COMMON_MESSAGE_PUMP_MOJO_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/common/message_pump_mojo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698