| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "core/events/ScopedEventQueue.h" | 35 #include "core/events/ScopedEventQueue.h" |
| 36 #include "core/layout/LayoutText.h" | 36 #include "core/layout/LayoutText.h" |
| 37 #include "core/layout/LayoutTextCombine.h" | 37 #include "core/layout/LayoutTextCombine.h" |
| 38 #include "core/layout/svg/LayoutSVGInlineText.h" | 38 #include "core/layout/svg/LayoutSVGInlineText.h" |
| 39 #include "core/svg/SVGForeignObjectElement.h" | 39 #include "core/svg/SVGForeignObjectElement.h" |
| 40 #include "wtf/text/CString.h" | 40 #include "wtf/text/CString.h" |
| 41 #include "wtf/text/StringBuilder.h" | 41 #include "wtf/text/StringBuilder.h" |
| 42 | 42 |
| 43 namespace blink { | 43 namespace blink { |
| 44 | 44 |
| 45 #if ENABLE(OILPAN) | |
| 46 namespace { | |
| 47 // If the external string kept by a Text node exceed this threshold length, | |
| 48 // Oilpan is informed. External allocation amounts owned by heap objects are | |
| 49 // taken into account when scheduling urgent Oilpan GCs. | |
| 50 // | |
| 51 // FIXME: having only Text nodes with strings above an ad-hoc local threshold | |
| 52 // influence Oilpan's GC behavior isn't a satisfactory long-term solution. | |
| 53 // But code that allocates a lot of Text nodes in tight loops, and not much more
, | |
| 54 // we do have to trigger Oilpan GCs to avoid PartitionAlloc OOMs. The accounting | |
| 55 // does add overhead on the allocation of every Text node however, so for now, o
nly | |
| 56 // register those above the given threshold. TBC. | |
| 57 const size_t stringLengthThreshold = 256; | |
| 58 | |
| 59 void increaseExternallyAllocatedBytesIfNeeded(size_t length) | |
| 60 { | |
| 61 if (length > stringLengthThreshold) | |
| 62 Heap::increaseExternallyAllocatedBytes(length); | |
| 63 } | |
| 64 | |
| 65 void increaseExternallyAllocatedBytesAliveIfNeeded(size_t length) | |
| 66 { | |
| 67 if (length > stringLengthThreshold) | |
| 68 Heap::increaseExternallyAllocatedBytesAlive(length); | |
| 69 } | |
| 70 | |
| 71 } // namespace | |
| 72 #endif | |
| 73 | |
| 74 PassRefPtrWillBeRawPtr<Text> Text::create(Document& document, const String& data
) | 45 PassRefPtrWillBeRawPtr<Text> Text::create(Document& document, const String& data
) |
| 75 { | 46 { |
| 76 #if ENABLE(OILPAN) | |
| 77 increaseExternallyAllocatedBytesIfNeeded(data.length()); | |
| 78 #endif | |
| 79 return adoptRefWillBeNoop(new Text(document, data, CreateText)); | 47 return adoptRefWillBeNoop(new Text(document, data, CreateText)); |
| 80 } | 48 } |
| 81 | 49 |
| 82 PassRefPtrWillBeRawPtr<Text> Text::createEditingText(Document& document, const S
tring& data) | 50 PassRefPtrWillBeRawPtr<Text> Text::createEditingText(Document& document, const S
tring& data) |
| 83 { | 51 { |
| 84 #if ENABLE(OILPAN) | |
| 85 increaseExternallyAllocatedBytesIfNeeded(data.length()); | |
| 86 #endif | |
| 87 return adoptRefWillBeNoop(new Text(document, data, CreateEditingText)); | 52 return adoptRefWillBeNoop(new Text(document, data, CreateEditingText)); |
| 88 } | 53 } |
| 89 | 54 |
| 90 PassRefPtrWillBeRawPtr<Node> Text::mergeNextSiblingNodesIfPossible() | 55 PassRefPtrWillBeRawPtr<Node> Text::mergeNextSiblingNodesIfPossible() |
| 91 { | 56 { |
| 92 RefPtrWillBeRawPtr<Node> protect(this); | 57 RefPtrWillBeRawPtr<Node> protect(this); |
| 93 | 58 |
| 94 // Remove empty text nodes. | 59 // Remove empty text nodes. |
| 95 if (!length()) { | 60 if (!length()) { |
| 96 // Care must be taken to get the next node before removing the current n
ode. | 61 // Care must be taken to get the next node before removing the current n
ode. |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 textRenderer->setTextWithOffset(dataImpl(), offsetOfReplacedData, lengthOfRe
placedData); | 403 textRenderer->setTextWithOffset(dataImpl(), offsetOfReplacedData, lengthOfRe
placedData); |
| 439 } | 404 } |
| 440 | 405 |
| 441 PassRefPtrWillBeRawPtr<Text> Text::cloneWithData(const String& data) | 406 PassRefPtrWillBeRawPtr<Text> Text::cloneWithData(const String& data) |
| 442 { | 407 { |
| 443 return create(document(), data); | 408 return create(document(), data); |
| 444 } | 409 } |
| 445 | 410 |
| 446 DEFINE_TRACE(Text) | 411 DEFINE_TRACE(Text) |
| 447 { | 412 { |
| 448 #if ENABLE(OILPAN) | |
| 449 increaseExternallyAllocatedBytesAliveIfNeeded(m_data.length()); | |
| 450 #endif | |
| 451 CharacterData::trace(visitor); | 413 CharacterData::trace(visitor); |
| 452 } | 414 } |
| 453 | 415 |
| 454 #ifndef NDEBUG | 416 #ifndef NDEBUG |
| 455 void Text::formatForDebugger(char *buffer, unsigned length) const | 417 void Text::formatForDebugger(char *buffer, unsigned length) const |
| 456 { | 418 { |
| 457 StringBuilder result; | 419 StringBuilder result; |
| 458 String s; | 420 String s; |
| 459 | 421 |
| 460 result.append(nodeName()); | 422 result.append(nodeName()); |
| 461 | 423 |
| 462 s = data(); | 424 s = data(); |
| 463 if (s.length() > 0) { | 425 if (s.length() > 0) { |
| 464 if (result.length()) | 426 if (result.length()) |
| 465 result.appendLiteral("; "); | 427 result.appendLiteral("; "); |
| 466 result.appendLiteral("value="); | 428 result.appendLiteral("value="); |
| 467 result.append(s); | 429 result.append(s); |
| 468 } | 430 } |
| 469 | 431 |
| 470 strncpy(buffer, result.toString().utf8().data(), length - 1); | 432 strncpy(buffer, result.toString().utf8().data(), length - 1); |
| 471 } | 433 } |
| 472 #endif | 434 #endif |
| 473 | 435 |
| 474 } // namespace blink | 436 } // namespace blink |
| OLD | NEW |