Commit 60526238 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Remove dead code in line_ending.{h,cc}

* Remove the CString-version of NormalizeLineEndingsToCRLF()
  It's not used.

* Remove CStringBuffer.
  Only the CString NormalizeLineEndingsToCRLF() used it.

* Fold VectorCharAppendBuffer into InternalNormalizeLineEndingsToCRLF()
  OutputBuffer abstraction isn't necessary due to the removal of
  CStringBuffer, and InternalNormalizeLineEndingsToCRLF() is the only
  user of OutputBuffer.

* Wrap InternalNormalizeLineEndingsToCRLF() with OS_WIN.
  It is used only on Windows.

This CL has no behavior changes.

Change-Id: I01d6177601f8be5fd5137f1554e7824080422d8f
Reviewed-on: https://chromium-review.googlesource.com/1072222Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561776}
parent b6f6b015
......@@ -41,55 +41,6 @@
namespace blink {
namespace {
class OutputBuffer {
STACK_ALLOCATED();
DISALLOW_COPY_AND_ASSIGN(OutputBuffer);
public:
OutputBuffer() = default;
virtual char* Allocate(size_t) = 0;
virtual void Copy(const CString&) = 0;
virtual ~OutputBuffer() = default;
};
class CStringBuffer final : public OutputBuffer {
public:
CStringBuffer(CString& buffer) : buffer_(buffer) {}
~CStringBuffer() override = default;
char* Allocate(size_t size) override {
char* ptr;
buffer_ = CString::CreateUninitialized(size, ptr);
return ptr;
}
void Copy(const CString& source) override { buffer_ = source; }
const CString& Buffer() const { return buffer_; }
private:
CString buffer_;
};
class VectorCharAppendBuffer final : public OutputBuffer {
public:
VectorCharAppendBuffer(Vector<char>& buffer) : buffer_(buffer) {}
~VectorCharAppendBuffer() override = default;
char* Allocate(size_t size) override {
size_t old_size = buffer_.size();
buffer_.Grow(old_size + size);
return buffer_.data() + old_size;
}
void Copy(const CString& source) override {
buffer_.Append(source.data(), source.length());
}
private:
Vector<char>& buffer_;
};
template <typename CharType>
size_t RequiredSizeForCRLF(const CharType* data, size_t length) {
size_t new_len = 0;
......@@ -138,19 +89,24 @@ void NormalizeToCRLF(const CharType* src, size_t src_length, CharType* q) {
}
}
#if defined(OS_WIN)
void InternalNormalizeLineEndingsToCRLF(const CString& from,
OutputBuffer& buffer) {
Vector<char>& buffer) {
size_t new_len = RequiredSizeForCRLF(from.data(), from.length());
if (new_len < from.length())
return;
if (new_len == from.length()) {
buffer.Copy(from);
buffer.Append(from.data(), from.length());
return;
}
NormalizeToCRLF(from.data(), from.length(), buffer.Allocate(new_len));
size_t old_buffer_size = buffer.size();
buffer.Grow(old_buffer_size + new_len);
char* write_position = buffer.data() + old_buffer_size;
NormalizeToCRLF(from.data(), from.length(), write_position);
}
#endif // defined(OS_WIN)
} // namespace
......@@ -203,15 +159,6 @@ void NormalizeLineEndingsToLF(const CString& from, Vector<char>& result) {
}
}
CString NormalizeLineEndingsToCRLF(const CString& from) {
if (!from.length())
return from;
CString result;
CStringBuffer buffer(result);
InternalNormalizeLineEndingsToCRLF(from, buffer);
return buffer.Buffer();
}
String NormalizeLineEndingsToCRLF(const String& src) {
size_t length = src.length();
if (length == 0)
......@@ -234,8 +181,7 @@ String NormalizeLineEndingsToCRLF(const String& src) {
void NormalizeLineEndingsToNative(const CString& from, Vector<char>& result) {
#if defined(OS_WIN)
VectorCharAppendBuffer buffer(result);
InternalNormalizeLineEndingsToCRLF(from, buffer);
InternalNormalizeLineEndingsToCRLF(from, result);
#else
NormalizeLineEndingsToLF(from, result);
#endif
......
......@@ -39,7 +39,6 @@
namespace blink {
// Normalize all line-endings in the given string to CRLF.
PLATFORM_EXPORT CString NormalizeLineEndingsToCRLF(const CString& from);
PLATFORM_EXPORT String NormalizeLineEndingsToCRLF(const String& from);
// Normalize all line-endings in the given string to LF and append the result to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment