| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights | 2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2012 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 // The +1 is for the terminating NUL character. | 44 // The +1 is for the terminating NUL character. |
| 45 size_t size = sizeof(CStringImpl) + length + 1; | 45 size_t size = sizeof(CStringImpl) + length + 1; |
| 46 CStringImpl* buffer = static_cast<CStringImpl*>( | 46 CStringImpl* buffer = static_cast<CStringImpl*>( |
| 47 Partitions::bufferMalloc(size, WTF_HEAP_PROFILER_TYPE_NAME(CStringImpl))); | 47 Partitions::bufferMalloc(size, WTF_HEAP_PROFILER_TYPE_NAME(CStringImpl))); |
| 48 data = reinterpret_cast<char*>(buffer + 1); | 48 data = reinterpret_cast<char*>(buffer + 1); |
| 49 data[length] = '\0'; | 49 data[length] = '\0'; |
| 50 return adoptRef(new (buffer) CStringImpl(length)); | 50 return adoptRef(new (buffer) CStringImpl(length)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 PassRefPtr<CStringImpl> CStringImpl::createUninitializedCHECK(size_t length, |
| 54 char*& data) { |
| 55 // TODO(esprehn): This doesn't account for the NUL. |
| 56 CHECK_LT(length, (numeric_limits<unsigned>::max() - sizeof(CStringImpl))); |
| 57 |
| 58 // The +1 is for the terminating NUL character. |
| 59 size_t size = sizeof(CStringImpl) + length + 1; |
| 60 CStringImpl* buffer = static_cast<CStringImpl*>( |
| 61 Partitions::bufferMalloc(size, WTF_HEAP_PROFILER_TYPE_NAME(CStringImpl))); |
| 62 data = reinterpret_cast<char*>(buffer + 1); |
| 63 data[length] = '\0'; |
| 64 return adoptRef(new (buffer) CStringImpl(length)); |
| 65 } |
| 66 |
| 53 void CStringImpl::operator delete(void* ptr) { | 67 void CStringImpl::operator delete(void* ptr) { |
| 54 Partitions::bufferFree(ptr); | 68 Partitions::bufferFree(ptr); |
| 55 } | 69 } |
| 56 | 70 |
| 57 CString::CString(const char* chars, size_t length) { | 71 CString::CString(const char* chars, size_t length) { |
| 58 if (!chars) { | 72 if (!chars) { |
| 59 DCHECK_EQ(length, 0u); | 73 DCHECK_EQ(length, 0u); |
| 60 return; | 74 return; |
| 61 } | 75 } |
| 62 char* data; | 76 char* data; |
| 63 m_buffer = CStringImpl::createUninitialized(length, data); | 77 if (rand() % 2) { |
| 78 m_buffer = CStringImpl::createUninitialized(length, data); |
| 79 } else { |
| 80 m_buffer = CStringImpl::createUninitializedCHECK(length, data); |
| 81 } |
| 64 memcpy(data, chars, length); | 82 memcpy(data, chars, length); |
| 65 } | 83 } |
| 66 | 84 |
| 67 bool CString::isSafeToSendToAnotherThread() const { | 85 bool CString::isSafeToSendToAnotherThread() const { |
| 68 return !m_buffer || m_buffer->hasOneRef(); | 86 return !m_buffer || m_buffer->hasOneRef(); |
| 69 } | 87 } |
| 70 | 88 |
| 71 bool operator==(const CString& a, const CString& b) { | 89 bool operator==(const CString& a, const CString& b) { |
| 72 if (a.isNull() != b.isNull()) | 90 if (a.isNull() != b.isNull()) |
| 73 return false; | 91 return false; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 ostream.setf(std::ios::uppercase); | 138 ostream.setf(std::ios::uppercase); |
| 121 ostream << (character & 0xff); | 139 ostream << (character & 0xff); |
| 122 } | 140 } |
| 123 break; | 141 break; |
| 124 } | 142 } |
| 125 } | 143 } |
| 126 return ostream << '"'; | 144 return ostream << '"'; |
| 127 } | 145 } |
| 128 | 146 |
| 129 } // namespace WTF | 147 } // namespace WTF |
| OLD | NEW |