Commit 7ed3b6e2 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Cleanup string-stream module.

R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/219173002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20344 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 8b304a68
// Copyright 2012 the V8 project authors. All rights reserved. // Copyright 2014 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Use of this source code is governed by a BSD-style license that can be
// modification, are permitted provided that the following conditions are // found in the LICENSE file.
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "v8.h"
#include "factory.h"
#include "string-stream.h" #include "string-stream.h"
#include "handles-inl.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
......
// Copyright 2006-2008 the V8 project authors. All rights reserved. // Copyright 2014 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without // Use of this source code is governed by a BSD-style license that can be
// modification, are permitted provided that the following conditions are // found in the LICENSE file.
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_STRING_STREAM_H_ #ifndef V8_STRING_STREAM_H_
#define V8_STRING_STREAM_H_ #define V8_STRING_STREAM_H_
#include "handles.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class StringAllocator { class StringAllocator {
public: public:
virtual ~StringAllocator() {} virtual ~StringAllocator() { }
// Allocate a number of bytes. // Allocate a number of bytes.
virtual char* allocate(unsigned bytes) = 0; virtual char* allocate(unsigned bytes) = 0;
// Allocate a larger number of bytes and copy the old buffer to the new one. // Allocate a larger number of bytes and copy the old buffer to the new one.
...@@ -46,11 +24,12 @@ class StringAllocator { ...@@ -46,11 +24,12 @@ class StringAllocator {
// Normal allocator uses new[] and delete[]. // Normal allocator uses new[] and delete[].
class HeapStringAllocator: public StringAllocator { class HeapStringAllocator V8_FINAL : public StringAllocator {
public: public:
~HeapStringAllocator() { DeleteArray(space_); } ~HeapStringAllocator() { DeleteArray(space_); }
char* allocate(unsigned bytes); virtual char* allocate(unsigned bytes) V8_OVERRIDE;
char* grow(unsigned* bytes); virtual char* grow(unsigned* bytes) V8_OVERRIDE;
private: private:
char* space_; char* space_;
}; };
...@@ -59,18 +38,19 @@ class HeapStringAllocator: public StringAllocator { ...@@ -59,18 +38,19 @@ class HeapStringAllocator: public StringAllocator {
// Allocator for use when no new c++ heap allocation is allowed. // Allocator for use when no new c++ heap allocation is allowed.
// Given a preallocated buffer up front and does no allocation while // Given a preallocated buffer up front and does no allocation while
// building message. // building message.
class NoAllocationStringAllocator: public StringAllocator { class NoAllocationStringAllocator V8_FINAL : public StringAllocator {
public: public:
NoAllocationStringAllocator(char* memory, unsigned size); NoAllocationStringAllocator(char* memory, unsigned size);
char* allocate(unsigned bytes) { return space_; } virtual char* allocate(unsigned bytes) V8_OVERRIDE { return space_; }
char* grow(unsigned* bytes); virtual char* grow(unsigned* bytes) V8_OVERRIDE;
private: private:
unsigned size_; unsigned size_;
char* space_; char* space_;
}; };
class FmtElm { class FmtElm V8_FINAL {
public: public:
FmtElm(int value) : type_(INT) { // NOLINT FmtElm(int value) : type_(INT) { // NOLINT
data_.u_int_ = value; data_.u_int_ = value;
...@@ -110,7 +90,7 @@ class FmtElm { ...@@ -110,7 +90,7 @@ class FmtElm {
}; };
class StringStream { class StringStream V8_FINAL {
public: public:
explicit StringStream(StringAllocator* allocator): explicit StringStream(StringAllocator* allocator):
allocator_(allocator), allocator_(allocator),
...@@ -120,9 +100,6 @@ class StringStream { ...@@ -120,9 +100,6 @@ class StringStream {
buffer_[0] = 0; buffer_[0] = 0;
} }
~StringStream() {
}
bool Put(char c); bool Put(char c);
bool Put(String* str); bool Put(String* str);
bool Put(String* str, int start, int end); bool Put(String* str, int start, int end);
...@@ -175,7 +152,6 @@ class StringStream { ...@@ -175,7 +152,6 @@ class StringStream {
static bool IsMentionedObjectCacheClear(Isolate* isolate); static bool IsMentionedObjectCacheClear(Isolate* isolate);
#endif #endif
static const int kInitialCapacity = 16; static const int kInitialCapacity = 16;
private: private:
...@@ -194,7 +170,7 @@ class StringStream { ...@@ -194,7 +170,7 @@ class StringStream {
// Utility class to print a list of items to a stream, divided by a separator. // Utility class to print a list of items to a stream, divided by a separator.
class SimpleListPrinter { class SimpleListPrinter V8_FINAL {
public: public:
explicit SimpleListPrinter(StringStream* stream, char separator = ',') { explicit SimpleListPrinter(StringStream* stream, char separator = ',') {
separator_ = separator; separator_ = separator;
...@@ -217,7 +193,6 @@ class SimpleListPrinter { ...@@ -217,7 +193,6 @@ class SimpleListPrinter {
StringStream* stream_; StringStream* stream_;
}; };
} } // namespace v8::internal } } // namespace v8::internal
#endif // V8_STRING_STREAM_H_ #endif // V8_STRING_STREAM_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment