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

Side by Side Diff: third_party/WebKit/Source/wtf/text/StringBuilder.cpp

Issue 1391153004: Make StringImpl's content immutable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bug fix: StringBuffer::release returns m_data directly Created 5 years, 2 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) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2012 Google Inc. All rights 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 m_string = StringImpl::empty(); 50 m_string = StringImpl::empty();
51 return; 51 return;
52 } 52 }
53 53
54 ASSERT(m_buffer && m_length <= m_buffer->length()); 54 ASSERT(m_buffer && m_length <= m_buffer->length());
55 if (m_length == m_buffer->length()) { 55 if (m_length == m_buffer->length()) {
56 m_string = m_buffer.release(); 56 m_string = m_buffer.release();
57 return; 57 return;
58 } 58 }
59 59
60 if (m_buffer->hasOneRef()) {
61 m_buffer->truncateAssumingIsolated(m_length);
62 m_string = m_buffer.release();
63 return;
64 }
65
66 m_string = m_buffer->substring(0, m_length); 60 m_string = m_buffer->substring(0, m_length);
67 } 61 }
68 62
69 String StringBuilder::reifySubstring(unsigned position, unsigned length) const 63 String StringBuilder::reifySubstring(unsigned position, unsigned length) const
70 { 64 {
71 ASSERT(m_string.isNull()); 65 ASSERT(m_string.isNull());
72 ASSERT(m_buffer); 66 ASSERT(m_buffer);
73 unsigned substringLength = std::min(length, m_length - position); 67 unsigned substringLength = std::min(length, m_length - position);
74 return m_buffer->substring(position, substringLength); 68 return m_buffer->substring(position, substringLength);
75 } 69 }
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (!canShrink()) 376 if (!canShrink())
383 return; 377 return;
384 if (m_is8Bit) 378 if (m_is8Bit)
385 reallocateBuffer<LChar>(m_length); 379 reallocateBuffer<LChar>(m_length);
386 else 380 else
387 reallocateBuffer<UChar>(m_length); 381 reallocateBuffer<UChar>(m_length);
388 m_string = m_buffer.release(); 382 m_string = m_buffer.release();
389 } 383 }
390 384
391 } // namespace WTF 385 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringBuffer.h ('k') | third_party/WebKit/Source/wtf/text/StringImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698