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

Unified Diff: runtime/platform/utils.h

Issue 16271010: Use 'new' in all the snapshot reallocation functions instead of realloc. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/vm/benchmark_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/platform/utils.h
===================================================================
--- runtime/platform/utils.h (revision 23633)
+++ runtime/platform/utils.h (working copy)
@@ -171,6 +171,27 @@
count <= (length - offset);
}
+ template <class ElementType>
+ static inline ElementType* Realloc(ElementType* old_data,
+ intptr_t old_len,
+ intptr_t new_len) {
+ if ((old_len * sizeof(ElementType)) >
+ (new_len * sizeof(ElementType))) {
+ FATAL2("Realloc overflow: "
+ "'old_size'=%"Pd",'new_size'=%"Pd,
+ (old_len * sizeof(ElementType)),
+ (new_len * sizeof(ElementType)));
+ }
+ ElementType* new_data = new ElementType[new_len];
+ if (old_data != NULL) {
+ memmove(reinterpret_cast<void*>(new_data),
+ reinterpret_cast<void*>(old_data),
+ (old_len * sizeof(ElementType)));
+ delete[] old_data;
+ }
+ return new_data;
+ }
+
// Utility functions for converting values from host endianess to
// big or little endian values.
static uint16_t HostToBigEndian16(uint16_t host_value);
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/vm/benchmark_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698