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

Side by Side Diff: src/list-inl.h

Issue 40105: Add an insert function to our list utility class. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/list.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 template<typename T, class P> 52 template<typename T, class P>
53 Vector<T> List<T, P>::AddBlock(const T& element, int count) { 53 Vector<T> List<T, P>::AddBlock(const T& element, int count) {
54 int start = length_; 54 int start = length_;
55 for (int i = 0; i < count; i++) 55 for (int i = 0; i < count; i++)
56 Add(element); 56 Add(element);
57 return Vector<T>(&data_[start], count); 57 return Vector<T>(&data_[start], count);
58 } 58 }
59 59
60 60
61 template<typename T, class P> 61 template<typename T, class P>
62 T& List<T, P>::Insert(int i, const T& element) {
63 int free_index = length_ - 1;
64 Add(last()); // Add grows the list if necessary.
65 while (free_index > i) {
66 data_[free_index] = data_[free_index - 1];
67 free_index--;
68 }
69 data_[free_index] = element;
70 }
71
72
73 template<typename T, class P>
62 T List<T, P>::Remove(int i) { 74 T List<T, P>::Remove(int i) {
63 T element = at(i); 75 T element = at(i);
64 length_--; 76 length_--;
65 while (i < length_) { 77 while (i < length_) {
66 data_[i] = data_[i + 1]; 78 data_[i] = data_[i + 1];
67 i++; 79 i++;
68 } 80 }
69 return element; 81 return element;
70 } 82 }
71 83
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ASSERT(capacity >= 0); 132 ASSERT(capacity >= 0);
121 data_ = (capacity > 0) ? NewData(capacity) : NULL; 133 data_ = (capacity > 0) ? NewData(capacity) : NULL;
122 capacity_ = capacity; 134 capacity_ = capacity;
123 length_ = 0; 135 length_ = 0;
124 } 136 }
125 137
126 138
127 } } // namespace v8::internal 139 } } // namespace v8::internal
128 140
129 #endif // V8_LIST_INL_H_ 141 #endif // V8_LIST_INL_H_
OLDNEW
« no previous file with comments | « src/list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698