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

Side by Side Diff: Source/core/editing/SurroundingText.cpp

Issue 544083002: Avoid allocating temporary ranges in connection with text and character iterators. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address review comments. Created 6 years, 3 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 | « Source/core/editing/SpellChecker.cpp ('k') | Source/core/editing/TextIterator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 PassRefPtrWillBeRawPtr<Range> SurroundingText::rangeFromContentOffsets(unsigned startOffsetInContent, unsigned endOffsetInContent) 102 PassRefPtrWillBeRawPtr<Range> SurroundingText::rangeFromContentOffsets(unsigned startOffsetInContent, unsigned endOffsetInContent)
103 { 103 {
104 if (startOffsetInContent >= endOffsetInContent || endOffsetInContent > conte nt().length()) 104 if (startOffsetInContent >= endOffsetInContent || endOffsetInContent > conte nt().length())
105 return nullptr; 105 return nullptr;
106 106
107 CharacterIterator iterator(m_contentRange.get()); 107 CharacterIterator iterator(m_contentRange.get());
108 108
109 ASSERT(!iterator.atEnd()); 109 ASSERT(!iterator.atEnd());
110 iterator.advance(startOffsetInContent); 110 iterator.advance(startOffsetInContent);
111 111
112 ASSERT(iterator.range()); 112 Position start = iterator.startPosition();
113 Position start = iterator.range()->startPosition();
114 113
115 ASSERT(!iterator.atEnd()); 114 ASSERT(!iterator.atEnd());
116 iterator.advance(endOffsetInContent - startOffsetInContent); 115 iterator.advance(endOffsetInContent - startOffsetInContent);
117 116
118 ASSERT(iterator.range()); 117 Position end = iterator.startPosition();
119 Position end = iterator.range()->startPosition();
120 118
121 ASSERT(start.document()); 119 ASSERT(start.document());
122 return Range::create(*start.document(), start, end); 120 return Range::create(*start.document(), start, end);
123 } 121 }
124 122
125 String SurroundingText::content() const 123 String SurroundingText::content() const
126 { 124 {
127 if (m_contentRange) 125 if (m_contentRange)
128 return m_contentRange->text(); 126 return m_contentRange->text();
129 return String(); 127 return String();
130 } 128 }
131 129
132 unsigned SurroundingText::startOffsetInContent() const 130 unsigned SurroundingText::startOffsetInContent() const
133 { 131 {
134 return m_startOffsetInContent; 132 return m_startOffsetInContent;
135 } 133 }
136 134
137 unsigned SurroundingText::endOffsetInContent() const 135 unsigned SurroundingText::endOffsetInContent() const
138 { 136 {
139 return m_endOffsetInContent; 137 return m_endOffsetInContent;
140 } 138 }
141 139
142 } // namespace blink 140 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/SpellChecker.cpp ('k') | Source/core/editing/TextIterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698