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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8StringResource.h

Issue 2232083002: Fix incorrect usage of StringImpl::sizeInBytes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: size_teeee Created 4 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 30 matching lines...) Expand all
41 USING_FAST_MALLOC(WebCoreStringResourceBase); 41 USING_FAST_MALLOC(WebCoreStringResourceBase);
42 WTF_MAKE_NONCOPYABLE(WebCoreStringResourceBase); 42 WTF_MAKE_NONCOPYABLE(WebCoreStringResourceBase);
43 public: 43 public:
44 explicit WebCoreStringResourceBase(const String& string) 44 explicit WebCoreStringResourceBase(const String& string)
45 : m_plainString(string) 45 : m_plainString(string)
46 { 46 {
47 #if ENABLE(ASSERT) 47 #if ENABLE(ASSERT)
48 m_threadId = WTF::currentThread(); 48 m_threadId = WTF::currentThread();
49 #endif 49 #endif
50 ASSERT(!string.isNull()); 50 ASSERT(!string.isNull());
51 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(memoryC onsumption(string)); 51 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(string. charactersSizeInBytes());
52 } 52 }
53 53
54 explicit WebCoreStringResourceBase(const AtomicString& string) 54 explicit WebCoreStringResourceBase(const AtomicString& string)
55 : m_plainString(string.getString()) 55 : m_plainString(string.getString())
56 , m_atomicString(string) 56 , m_atomicString(string)
57 { 57 {
58 #if ENABLE(ASSERT) 58 #if ENABLE(ASSERT)
59 m_threadId = WTF::currentThread(); 59 m_threadId = WTF::currentThread();
60 #endif 60 #endif
61 ASSERT(!string.isNull()); 61 ASSERT(!string.isNull());
62 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(memoryC onsumption(string)); 62 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(string. charactersSizeInBytes());
63 } 63 }
64 64
65 virtual ~WebCoreStringResourceBase() 65 virtual ~WebCoreStringResourceBase()
66 { 66 {
67 #if ENABLE(ASSERT) 67 #if ENABLE(ASSERT)
68 ASSERT(m_threadId == WTF::currentThread()); 68 ASSERT(m_threadId == WTF::currentThread());
69 #endif 69 #endif
70 int reducedExternalMemory = -memoryConsumption(m_plainString); 70 int64_t reducedExternalMemory = m_plainString.charactersSizeInBytes();
71 if (m_plainString.impl() != m_atomicString.impl() && !m_atomicString.isN ull()) 71 if (m_plainString.impl() != m_atomicString.impl() && !m_atomicString.isN ull())
72 reducedExternalMemory -= memoryConsumption(m_atomicString); 72 reducedExternalMemory += m_atomicString.charactersSizeInBytes();
73 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(reduced ExternalMemory); 73 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-reduce dExternalMemory);
74 } 74 }
75 75
76 const String& webcoreString() { return m_plainString; } 76 const String& webcoreString() { return m_plainString; }
77 77
78 const AtomicString& getAtomicString() 78 const AtomicString& getAtomicString()
79 { 79 {
80 #if ENABLE(ASSERT) 80 #if ENABLE(ASSERT)
81 ASSERT(m_threadId == WTF::currentThread()); 81 ASSERT(m_threadId == WTF::currentThread());
82 #endif 82 #endif
83 if (m_atomicString.isNull()) { 83 if (m_atomicString.isNull()) {
84 m_atomicString = AtomicString(m_plainString); 84 m_atomicString = AtomicString(m_plainString);
85 ASSERT(!m_atomicString.isNull()); 85 ASSERT(!m_atomicString.isNull());
86 if (m_plainString.impl() != m_atomicString.impl()) 86 if (m_plainString.impl() != m_atomicString.impl())
87 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory (memoryConsumption(m_atomicString.getString())); 87 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory (m_atomicString.charactersSizeInBytes());
88 } 88 }
89 return m_atomicString; 89 return m_atomicString;
90 } 90 }
91 91
92 protected: 92 protected:
93 // A shallow copy of the string. Keeps the string buffer alive until the V8 engine garbage collects it. 93 // A shallow copy of the string. Keeps the string buffer alive until the V8 engine garbage collects it.
94 String m_plainString; 94 String m_plainString;
95 // If this string is atomic or has been made atomic earlier the 95 // If this string is atomic or has been made atomic earlier the
96 // atomic string is held here. In the case where the string starts 96 // atomic string is held here. In the case where the string starts
97 // off non-atomic and becomes atomic later it is necessary to keep 97 // off non-atomic and becomes atomic later it is necessary to keep
98 // the original string alive because v8 may keep derived pointers 98 // the original string alive because v8 may keep derived pointers
99 // into that string. 99 // into that string.
100 AtomicString m_atomicString; 100 AtomicString m_atomicString;
101 101
102 private: 102 private:
103 static int memoryConsumption(const String& string)
104 {
105 return string.length() * (string.is8Bit() ? sizeof(LChar) : sizeof(UChar ));
106 }
107 #if ENABLE(ASSERT) 103 #if ENABLE(ASSERT)
108 WTF::ThreadIdentifier m_threadId; 104 WTF::ThreadIdentifier m_threadId;
109 #endif 105 #endif
110 }; 106 };
111 107
112 class WebCoreStringResource16 final : public WebCoreStringResourceBase, public v 8::String::ExternalStringResource { 108 class WebCoreStringResource16 final : public WebCoreStringResourceBase, public v 8::String::ExternalStringResource {
113 WTF_MAKE_NONCOPYABLE(WebCoreStringResource16); 109 WTF_MAKE_NONCOPYABLE(WebCoreStringResource16);
114 public: 110 public:
115 explicit WebCoreStringResource16(const String& string) 111 explicit WebCoreStringResource16(const String& string)
116 : WebCoreStringResourceBase(string) 112 : WebCoreStringResourceBase(string)
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 316 }
321 317
322 template<> inline String V8StringResource<TreatNullAndUndefinedAsNullString>::fa llbackString() const 318 template<> inline String V8StringResource<TreatNullAndUndefinedAsNullString>::fa llbackString() const
323 { 319 {
324 return String(); 320 return String();
325 } 321 }
326 322
327 } // namespace blink 323 } // namespace blink
328 324
329 #endif // V8StringResource_h 325 #endif // V8StringResource_h
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/string_traits_wtf.cc ('k') | third_party/WebKit/Source/core/fetch/ScriptResource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698