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

Unified Diff: src/utils.h

Issue 1940: Replaced calls to functions that msvc consider deprecated. Used... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/top.cc ('k') | src/utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils.h
===================================================================
--- src/utils.h (revision 280)
+++ src/utils.h (working copy)
@@ -279,6 +279,10 @@
ASSERT(length == 0 || (length > 0 && data != NULL));
}
+ static Vector<T> New(int length) {
+ return Vector<T>(NewArray<T>(length), length);
+ }
+
// Returns the length of the vector.
int length() const { return length_; }
@@ -310,6 +314,11 @@
length_ = 0;
}
+ inline Vector<T> operator+(int offset) {
+ ASSERT(offset < length_);
+ return Vector<T>(start_ + offset, length_ - offset);
+ }
+
// Factory method for creating empty vectors.
static Vector<T> empty() { return Vector<T>(NULL, 0); }
@@ -319,6 +328,15 @@
};
+template <typename T, int size>
+class EmbeddedVector : public Vector<T> {
+ public:
+ EmbeddedVector() : Vector<T>(buffer_, size) { }
+ private:
+ T buffer_[size];
+};
+
+
inline Vector<const char> CStrVector(const char* data) {
return Vector<const char>(data, strlen(data));
}
@@ -327,6 +345,11 @@
return Vector<char>(data, strlen(data));
}
+inline Vector<char> MutableCStrVector(char* data, int max) {
+ int length = strlen(data);
+ return Vector<char>(data, (length < max) ? length : max);
+}
+
template <typename T>
inline Vector< Handle<Object> > HandleVector(v8::internal::Handle<T>* elms,
int length) {
@@ -369,11 +392,11 @@
explicit StringBuilder(int size);
StringBuilder(char* buffer, int size)
- : buffer_(buffer), size_(size), position_(0) { }
+ : buffer_(buffer, size), position_(0) { }
~StringBuilder() { if (!is_finalized()) Finalize(); }
- int size() const { return size_; }
+ int size() const { return buffer_.length(); }
// Get the current position in the builder.
int position() const {
@@ -389,7 +412,7 @@
// instead.
void AddCharacter(char c) {
ASSERT(c != '\0');
- ASSERT(!is_finalized() && position_ < size_);
+ ASSERT(!is_finalized() && position_ < buffer_.length());
buffer_[position_++] = c;
}
@@ -412,8 +435,7 @@
char* Finalize();
private:
- char* buffer_;
- int size_;
+ Vector<char> buffer_;
int position_;
bool is_finalized() const { return position_ < 0; }
« no previous file with comments | « src/top.cc ('k') | src/utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698