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

Side by Side Diff: src/allocation.cc

Issue 48127: Introducing a new StrNDup function that uses new[] for when we dispose the re... (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/allocation.h ('k') | src/d8-readline.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 2008 the V8 project authors. All rights reserved. 1 // Copyright 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 char* StrDup(const char* str) { 81 char* StrDup(const char* str) {
82 int length = strlen(str); 82 int length = strlen(str);
83 char* result = NewArray<char>(length + 1); 83 char* result = NewArray<char>(length + 1);
84 memcpy(result, str, length * kCharSize); 84 memcpy(result, str, length * kCharSize);
85 result[length] = '\0'; 85 result[length] = '\0';
86 return result; 86 return result;
87 } 87 }
88 88
89 89
90 char* StrNDup(const char* str, size_t n) {
91 size_t length = strlen(str);
92 if (n < length) length = n;
93 char* result = NewArray<char>(length + 1);
94 memcpy(result, str, length * kCharSize);
95 result[length] = '\0';
96 return result;
97 }
98
99
90 int NativeAllocationChecker::allocation_disallowed_ = 0; 100 int NativeAllocationChecker::allocation_disallowed_ = 0;
91 101
92 102
93 PreallocatedStorage PreallocatedStorage::in_use_list_(0); 103 PreallocatedStorage PreallocatedStorage::in_use_list_(0);
94 PreallocatedStorage PreallocatedStorage::free_list_(0); 104 PreallocatedStorage PreallocatedStorage::free_list_(0);
95 bool PreallocatedStorage::preallocated_ = false; 105 bool PreallocatedStorage::preallocated_ = false;
96 106
97 107
98 void PreallocatedStorage::Init(size_t size) { 108 void PreallocatedStorage::Init(size_t size) {
99 ASSERT(free_list_.next_ == &free_list_); 109 ASSERT(free_list_.next_ == &free_list_);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 previous_->next_ = next_; 188 previous_->next_ = next_;
179 } 189 }
180 190
181 191
182 PreallocatedStorage::PreallocatedStorage(size_t size) 192 PreallocatedStorage::PreallocatedStorage(size_t size)
183 : size_(size) { 193 : size_(size) {
184 previous_ = next_ = this; 194 previous_ = next_ = this;
185 } 195 }
186 196
187 } } // namespace v8::internal 197 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/allocation.h ('k') | src/d8-readline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698