mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:42:45 +00:00 
			
		
		
		
	Sprinkle use of AK::Vector in various places.
Some of these are less helpful than others. Avoiding a bunch of mallocs in the event loop wakeup code is definitely nice.
This commit is contained in:
		
							parent
							
								
									7faf8fabf2
								
							
						
					
					
						commit
						5eedb22834
					
				
					 17 changed files with 53 additions and 50 deletions
				
			
		|  | @ -26,6 +26,7 @@ int thumbnail_thread(void* model_ptr) | ||||||
|         Vector<String> to_generate; |         Vector<String> to_generate; | ||||||
|         { |         { | ||||||
|             LOCKER(thumbnail_cache().lock()); |             LOCKER(thumbnail_cache().lock()); | ||||||
|  |             to_generate.ensure_capacity(thumbnail_cache().resource().size()); | ||||||
|             for (auto& it : thumbnail_cache().resource()) { |             for (auto& it : thumbnail_cache().resource()) { | ||||||
|                 if (it.value) |                 if (it.value) | ||||||
|                     continue; |                     continue; | ||||||
|  |  | ||||||
|  | @ -87,9 +87,9 @@ void IRCClient::receive_from_server() | ||||||
| void IRCClient::process_line(ByteBuffer&& line) | void IRCClient::process_line(ByteBuffer&& line) | ||||||
| { | { | ||||||
|     Message msg; |     Message msg; | ||||||
|     Vector<char> prefix; |     Vector<char, 32> prefix; | ||||||
|     Vector<char> command; |     Vector<char, 32> command; | ||||||
|     Vector<char> current_parameter; |     Vector<char, 256> current_parameter; | ||||||
|     enum { |     enum { | ||||||
|         Start, |         Start, | ||||||
|         InPrefix, |         InPrefix, | ||||||
|  |  | ||||||
|  | @ -193,7 +193,7 @@ void ProcessModel::update() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     m_pids.clear(); |     m_pids.clear(); | ||||||
|     Vector<pid_t> pids_to_remove; |     Vector<pid_t, 16> pids_to_remove; | ||||||
|     for (auto& it : m_processes) { |     for (auto& it : m_processes) { | ||||||
|         if (!live_pids.contains(it.key)) { |         if (!live_pids.contains(it.key)) { | ||||||
|             pids_to_remove.append(it.key); |             pids_to_remove.append(it.key); | ||||||
|  |  | ||||||
|  | @ -136,7 +136,7 @@ static inline Color lookup_color(unsigned color) | ||||||
|     return Color::from_rgb(xterm_colors[color]); |     return Color::from_rgb(xterm_colors[color]); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$m(const Vector<unsigned>& params) | void Terminal::escape$m(const ParamVector& params) | ||||||
| { | { | ||||||
|     if (params.size() == 3 && params[1] == 5) { |     if (params.size() == 3 && params[1] == 5) { | ||||||
|         if (params[0] == 38) { |         if (params[0] == 38) { | ||||||
|  | @ -183,25 +183,25 @@ void Terminal::escape$m(const Vector<unsigned>& params) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$s(const Vector<unsigned>&) | void Terminal::escape$s(const ParamVector&) | ||||||
| { | { | ||||||
|     m_saved_cursor_row = m_cursor_row; |     m_saved_cursor_row = m_cursor_row; | ||||||
|     m_saved_cursor_column = m_cursor_column; |     m_saved_cursor_column = m_cursor_column; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$u(const Vector<unsigned>&) | void Terminal::escape$u(const ParamVector&) | ||||||
| { | { | ||||||
|     set_cursor(m_saved_cursor_row, m_saved_cursor_column); |     set_cursor(m_saved_cursor_row, m_saved_cursor_column); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$t(const Vector<unsigned>& params) | void Terminal::escape$t(const ParamVector& params) | ||||||
| { | { | ||||||
|     if (params.size() < 1) |     if (params.size() < 1) | ||||||
|         return; |         return; | ||||||
|     dbgprintf("FIXME: escape$t: Ps: %u\n", params[0]); |     dbgprintf("FIXME: escape$t: Ps: %u\n", params[0]); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$r(const Vector<unsigned>& params) | void Terminal::escape$r(const ParamVector& params) | ||||||
| { | { | ||||||
|     unsigned top = 1; |     unsigned top = 1; | ||||||
|     unsigned bottom = m_rows; |     unsigned bottom = m_rows; | ||||||
|  | @ -212,7 +212,7 @@ void Terminal::escape$r(const Vector<unsigned>& params) | ||||||
|     dbgprintf("FIXME: escape$r: Set scrolling region: %u-%u\n", top, bottom); |     dbgprintf("FIXME: escape$r: Set scrolling region: %u-%u\n", top, bottom); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$H(const Vector<unsigned>& params) | void Terminal::escape$H(const ParamVector& params) | ||||||
| { | { | ||||||
|     unsigned row = 1; |     unsigned row = 1; | ||||||
|     unsigned col = 1; |     unsigned col = 1; | ||||||
|  | @ -223,7 +223,7 @@ void Terminal::escape$H(const Vector<unsigned>& params) | ||||||
|     set_cursor(row - 1, col - 1); |     set_cursor(row - 1, col - 1); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$A(const Vector<unsigned>& params) | void Terminal::escape$A(const ParamVector& params) | ||||||
| { | { | ||||||
|     int num = 1; |     int num = 1; | ||||||
|     if (params.size() >= 1) |     if (params.size() >= 1) | ||||||
|  | @ -236,7 +236,7 @@ void Terminal::escape$A(const Vector<unsigned>& params) | ||||||
|     set_cursor(new_row, m_cursor_column); |     set_cursor(new_row, m_cursor_column); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$B(const Vector<unsigned>& params) | void Terminal::escape$B(const ParamVector& params) | ||||||
| { | { | ||||||
|     int num = 1; |     int num = 1; | ||||||
|     if (params.size() >= 1) |     if (params.size() >= 1) | ||||||
|  | @ -249,7 +249,7 @@ void Terminal::escape$B(const Vector<unsigned>& params) | ||||||
|     set_cursor(new_row, m_cursor_column); |     set_cursor(new_row, m_cursor_column); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$C(const Vector<unsigned>& params) | void Terminal::escape$C(const ParamVector& params) | ||||||
| { | { | ||||||
|     int num = 1; |     int num = 1; | ||||||
|     if (params.size() >= 1) |     if (params.size() >= 1) | ||||||
|  | @ -262,7 +262,7 @@ void Terminal::escape$C(const Vector<unsigned>& params) | ||||||
|     set_cursor(m_cursor_row, new_column); |     set_cursor(m_cursor_row, new_column); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$D(const Vector<unsigned>& params) | void Terminal::escape$D(const ParamVector& params) | ||||||
| { | { | ||||||
|     int num = 1; |     int num = 1; | ||||||
|     if (params.size() >= 1) |     if (params.size() >= 1) | ||||||
|  | @ -275,7 +275,7 @@ void Terminal::escape$D(const Vector<unsigned>& params) | ||||||
|     set_cursor(m_cursor_row, new_column); |     set_cursor(m_cursor_row, new_column); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$G(const Vector<unsigned>& params) | void Terminal::escape$G(const ParamVector& params) | ||||||
| { | { | ||||||
|     int new_column = 1; |     int new_column = 1; | ||||||
|     if (params.size() >= 1) |     if (params.size() >= 1) | ||||||
|  | @ -285,7 +285,7 @@ void Terminal::escape$G(const Vector<unsigned>& params) | ||||||
|     set_cursor(m_cursor_row, new_column); |     set_cursor(m_cursor_row, new_column); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$d(const Vector<unsigned>& params) | void Terminal::escape$d(const ParamVector& params) | ||||||
| { | { | ||||||
|     int new_row = 1; |     int new_row = 1; | ||||||
|     if (params.size() >= 1) |     if (params.size() >= 1) | ||||||
|  | @ -295,7 +295,7 @@ void Terminal::escape$d(const Vector<unsigned>& params) | ||||||
|     set_cursor(new_row, m_cursor_column); |     set_cursor(new_row, m_cursor_column); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$X(const Vector<unsigned>& params) | void Terminal::escape$X(const ParamVector& params) | ||||||
| { | { | ||||||
|     // Erase characters (without moving cursor)
 |     // Erase characters (without moving cursor)
 | ||||||
|     int num = 1; |     int num = 1; | ||||||
|  | @ -309,7 +309,7 @@ void Terminal::escape$X(const Vector<unsigned>& params) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$K(const Vector<unsigned>& params) | void Terminal::escape$K(const ParamVector& params) | ||||||
| { | { | ||||||
|     int mode = 0; |     int mode = 0; | ||||||
|     if (params.size() >= 1) |     if (params.size() >= 1) | ||||||
|  | @ -336,7 +336,7 @@ void Terminal::escape$K(const Vector<unsigned>& params) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$J(const Vector<unsigned>& params) | void Terminal::escape$J(const ParamVector& params) | ||||||
| { | { | ||||||
|     int mode = 0; |     int mode = 0; | ||||||
|     if (params.size() >= 1) |     if (params.size() >= 1) | ||||||
|  | @ -370,7 +370,7 @@ void Terminal::escape$J(const Vector<unsigned>& params) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Terminal::escape$M(const Vector<unsigned>& params) | void Terminal::escape$M(const ParamVector& params) | ||||||
| { | { | ||||||
|     int count = 1; |     int count = 1; | ||||||
|     if (params.size() >= 1) |     if (params.size() >= 1) | ||||||
|  | @ -414,7 +414,7 @@ void Terminal::execute_escape_sequence(byte final) | ||||||
| { | { | ||||||
|     m_final = final; |     m_final = final; | ||||||
|     auto paramparts = String((const char*)m_parameters.data(), m_parameters.size()).split(';'); |     auto paramparts = String((const char*)m_parameters.data(), m_parameters.size()).split(';'); | ||||||
|     Vector<unsigned> params; |     ParamVector params; | ||||||
|     for (auto& parampart : paramparts) { |     for (auto& parampart : paramparts) { | ||||||
|         bool ok; |         bool ok; | ||||||
|         unsigned value = parse_uint(parampart, ok); |         unsigned value = parse_uint(parampart, ok); | ||||||
|  |  | ||||||
|  | @ -25,6 +25,8 @@ public: | ||||||
|     void apply_size_increments_to_window(GWindow&); |     void apply_size_increments_to_window(GWindow&); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  |     typedef Vector<unsigned, 4> ParamVector; | ||||||
|  | 
 | ||||||
|     virtual void event(CEvent&) override; |     virtual void event(CEvent&) override; | ||||||
|     virtual void paint_event(GPaintEvent&) override; |     virtual void paint_event(GPaintEvent&) override; | ||||||
|     virtual void resize_event(GResizeEvent&) override; |     virtual void resize_event(GResizeEvent&) override; | ||||||
|  | @ -42,22 +44,22 @@ private: | ||||||
|     void unimplemented_escape(); |     void unimplemented_escape(); | ||||||
|     void unimplemented_xterm_escape(); |     void unimplemented_xterm_escape(); | ||||||
| 
 | 
 | ||||||
|     void escape$A(const Vector<unsigned>&); |     void escape$A(const ParamVector&); | ||||||
|     void escape$B(const Vector<unsigned>&); |     void escape$B(const ParamVector&); | ||||||
|     void escape$C(const Vector<unsigned>&); |     void escape$C(const ParamVector&); | ||||||
|     void escape$D(const Vector<unsigned>&); |     void escape$D(const ParamVector&); | ||||||
|     void escape$H(const Vector<unsigned>&); |     void escape$H(const ParamVector&); | ||||||
|     void escape$J(const Vector<unsigned>&); |     void escape$J(const ParamVector&); | ||||||
|     void escape$K(const Vector<unsigned>&); |     void escape$K(const ParamVector&); | ||||||
|     void escape$M(const Vector<unsigned>&); |     void escape$M(const ParamVector&); | ||||||
|     void escape$G(const Vector<unsigned>&); |     void escape$G(const ParamVector&); | ||||||
|     void escape$X(const Vector<unsigned>&); |     void escape$X(const ParamVector&); | ||||||
|     void escape$d(const Vector<unsigned>&); |     void escape$d(const ParamVector&); | ||||||
|     void escape$m(const Vector<unsigned>&); |     void escape$m(const ParamVector&); | ||||||
|     void escape$s(const Vector<unsigned>&); |     void escape$s(const ParamVector&); | ||||||
|     void escape$u(const Vector<unsigned>&); |     void escape$u(const ParamVector&); | ||||||
|     void escape$t(const Vector<unsigned>&); |     void escape$t(const ParamVector&); | ||||||
|     void escape$r(const Vector<unsigned>&); |     void escape$r(const ParamVector&); | ||||||
| 
 | 
 | ||||||
|     void clear(); |     void clear(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2276,7 +2276,7 @@ void SharedBuffer::destroy_if_unused() | ||||||
| void Process::disown_all_shared_buffers() | void Process::disown_all_shared_buffers() | ||||||
| { | { | ||||||
|     LOCKER(shared_buffers().lock()); |     LOCKER(shared_buffers().lock()); | ||||||
|     Vector<SharedBuffer*> buffers_to_disown; |     Vector<SharedBuffer*, 32> buffers_to_disown; | ||||||
|     for (auto& it : shared_buffers().resource()) |     for (auto& it : shared_buffers().resource()) | ||||||
|         buffers_to_disown.append(it.value.ptr()); |         buffers_to_disown.append(it.value.ptr()); | ||||||
|     for (auto* shared_buffer : buffers_to_disown) |     for (auto* shared_buffer : buffers_to_disown) | ||||||
|  |  | ||||||
|  | @ -167,7 +167,7 @@ void Thread::finalize() | ||||||
| 
 | 
 | ||||||
| void Thread::finalize_dying_threads() | void Thread::finalize_dying_threads() | ||||||
| { | { | ||||||
|     Vector<Thread*> dying_threads; |     Vector<Thread*, 32> dying_threads; | ||||||
|     { |     { | ||||||
|         InterruptDisabler disabler; |         InterruptDisabler disabler; | ||||||
|         for_each_in_state(Thread::State::Dying, [&] (Thread& thread) { |         for_each_in_state(Thread::State::Dying, [&] (Thread& thread) { | ||||||
|  |  | ||||||
|  | @ -64,7 +64,7 @@ int execvp(const char* filename, char* const argv[]) | ||||||
| 
 | 
 | ||||||
| int execl(const char* filename, const char* arg0, ...) | int execl(const char* filename, const char* arg0, ...) | ||||||
| { | { | ||||||
|     Vector<const char*> args; |     Vector<const char*, 16> args; | ||||||
|     args.append(arg0); |     args.append(arg0); | ||||||
| 
 | 
 | ||||||
|     va_list ap; |     va_list ap; | ||||||
|  |  | ||||||
|  | @ -95,7 +95,7 @@ int CEventLoop::exec() | ||||||
|             wait_for_event(); |             wait_for_event(); | ||||||
|             do_processing(); |             do_processing(); | ||||||
|         } |         } | ||||||
|         Vector<QueuedEvent> events = move(m_queued_events); |         auto events = move(m_queued_events); | ||||||
|         for (auto& queued_event : events) { |         for (auto& queued_event : events) { | ||||||
|             auto* receiver = queued_event.receiver.ptr(); |             auto* receiver = queued_event.receiver.ptr(); | ||||||
|             auto& event = *queued_event.event; |             auto& event = *queued_event.event; | ||||||
|  |  | ||||||
|  | @ -52,7 +52,7 @@ private: | ||||||
|         WeakPtr<CObject> receiver; |         WeakPtr<CObject> receiver; | ||||||
|         OwnPtr<CEvent> event; |         OwnPtr<CEvent> event; | ||||||
|     }; |     }; | ||||||
|     Vector<QueuedEvent> m_queued_events; |     Vector<QueuedEvent, 64> m_queued_events; | ||||||
| 
 | 
 | ||||||
|     bool m_running { false }; |     bool m_running { false }; | ||||||
|     bool m_exit_requested { false }; |     bool m_exit_requested { false }; | ||||||
|  |  | ||||||
|  | @ -60,7 +60,7 @@ private: | ||||||
|     void handle_wm_event(const WSAPI_ServerMessage&, GWindow&); |     void handle_wm_event(const WSAPI_ServerMessage&, GWindow&); | ||||||
|     void connect_to_server(); |     void connect_to_server(); | ||||||
| 
 | 
 | ||||||
|     Vector<WSAPI_ServerMessage> m_unprocessed_messages; |     Vector<WSAPI_ServerMessage, 64> m_unprocessed_messages; | ||||||
|     static pid_t s_server_pid; |     static pid_t s_server_pid; | ||||||
|     static pid_t s_event_fd; |     static pid_t s_event_fd; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -76,7 +76,7 @@ struct GFileSystemModel::Node { | ||||||
| 
 | 
 | ||||||
|     String full_path(const GFileSystemModel& model) const |     String full_path(const GFileSystemModel& model) const | ||||||
|     { |     { | ||||||
|         Vector<String> lineage; |         Vector<String, 32> lineage; | ||||||
|         for (auto* ancestor = parent; ancestor; ancestor = ancestor->parent) { |         for (auto* ancestor = parent; ancestor; ancestor = ancestor->parent) { | ||||||
|             lineage.append(ancestor->name); |             lineage.append(ancestor->name); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -116,7 +116,7 @@ static String to_string(KeyCode key) | ||||||
| 
 | 
 | ||||||
| String GShortcut::to_string() const | String GShortcut::to_string() const | ||||||
| { | { | ||||||
|     Vector<String> parts; |     Vector<String, 8> parts; | ||||||
| 
 | 
 | ||||||
|     if (m_modifiers & Mod_Ctrl) |     if (m_modifiers & Mod_Ctrl) | ||||||
|         parts.append("Ctrl"); |         parts.append("Ctrl"); | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ void DisjointRectSet::add(const Rect& new_rect) | ||||||
| 
 | 
 | ||||||
| void DisjointRectSet::shatter() | void DisjointRectSet::shatter() | ||||||
| { | { | ||||||
|     Vector<Rect> output; |     Vector<Rect, 32> output; | ||||||
|     output.ensure_capacity(m_rects.size()); |     output.ensure_capacity(m_rects.size()); | ||||||
|     bool pass_had_intersections = false; |     bool pass_had_intersections = false; | ||||||
|     do { |     do { | ||||||
|  |  | ||||||
|  | @ -13,11 +13,11 @@ public: | ||||||
| 
 | 
 | ||||||
|     void clear() { m_rects.clear(); } |     void clear() { m_rects.clear(); } | ||||||
|     void clear_with_capacity() { m_rects.clear_with_capacity(); } |     void clear_with_capacity() { m_rects.clear_with_capacity(); } | ||||||
|     const Vector<Rect>& rects() const { return m_rects; } |     const Vector<Rect, 32>& rects() const { return m_rects; } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     void shatter(); |     void shatter(); | ||||||
| 
 | 
 | ||||||
|     Vector<Rect> m_rects; |     Vector<Rect, 32> m_rects; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -75,7 +75,7 @@ protected: | ||||||
| 
 | 
 | ||||||
|     Rect m_clip_origin; |     Rect m_clip_origin; | ||||||
|     Retained<GraphicsBitmap> m_target; |     Retained<GraphicsBitmap> m_target; | ||||||
|     Vector<State> m_state_stack; |     Vector<State, 4> m_state_stack; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class PainterStateSaver { | class PainterStateSaver { | ||||||
|  |  | ||||||
|  | @ -197,7 +197,7 @@ int do_dir_short(const char* path) | ||||||
|         return 1; |         return 1; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     Vector<String> names; |     Vector<String, 1024> names; | ||||||
|     int longest_name = 0; |     int longest_name = 0; | ||||||
|     while (auto* de = readdir(dirp)) { |     while (auto* de = readdir(dirp)) { | ||||||
|         if (de->d_name[0] == '.' && !flag_show_dotfiles) |         if (de->d_name[0] == '.' && !flag_show_dotfiles) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling