Skip to content

Commit

Permalink
Revert "AK: Made Strings reversible"
Browse files Browse the repository at this point in the history
This reverts commit 26e81ad.

We forgot to consider UTF-8 here. String is UTF-8 and we need to be
careful about things like this.
  • Loading branch information
awesomekling committed Sep 13, 2019
1 parent 2d1f3ec commit 09e89cc
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 28 deletions.
10 changes: 2 additions & 8 deletions AK/String.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ class String {
return m_impl->to_uppercase();
}

String reversed() const
{
if (!m_impl)
return String();
return m_impl->reversed();
}

Vector<String> split_limit(char separator, int limit) const;
Vector<String> split(char separator) const;
String substring(int start, int length) const;
Expand Down Expand Up @@ -234,6 +227,7 @@ struct Traits<String> : public GenericTraits<String> {
struct CaseInsensitiveStringTraits : public AK::Traits<String> {
static unsigned hash(const String& s) { return s.impl() ? s.to_lowercase().impl()->hash() : 0; }
static bool equals(const String& a, const String& b) { return a.to_lowercase() == b.to_lowercase(); }

};

inline bool operator<(const char* characters, const String& string)
Expand Down Expand Up @@ -270,5 +264,5 @@ inline bool operator<=(const char* characters, const String& string)

}

using AK::CaseInsensitiveStringTraits;
using AK::String;
using AK::CaseInsensitiveStringTraits;
17 changes: 1 addition & 16 deletions AK/StringImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "kmalloc.h"

#ifndef __serenity__
# include <new>
#include <new>
#endif

//#define DEBUG_STRINGIMPL
Expand Down Expand Up @@ -172,19 +172,4 @@ void StringImpl::compute_hash() const
m_has_hash = true;
}

NonnullRefPtr<StringImpl> StringImpl::reversed() const
{
if (m_length == 0)
return the_empty_stringimpl();

char* buffer;
const char* pos = &m_inline_buffer[m_length - 1];
auto new_impl = create_uninitialized(m_length, buffer);

for (int i = 0; i < m_length; i++)
buffer[i] = *pos--;

return new_impl;
}

}
4 changes: 1 addition & 3 deletions AK/StringImpl.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/RefCounted.h>
#include <AK/Types.h>
#include <AK/kmalloc.h>

Expand Down Expand Up @@ -44,8 +44,6 @@ class StringImpl : public RefCounted<StringImpl> {
return m_hash;
}

NonnullRefPtr<StringImpl> reversed() const;

private:
enum ConstructTheEmptyStringImplTag {
ConstructTheEmptyStringImpl
Expand Down
1 change: 0 additions & 1 deletion AK/Tests/TestString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ TEST_CASE(compare)
EXPECT(!("a" >= String("b")));
EXPECT("a" <= String("a"));
EXPECT(!("b" <= String("a")));
EXPECT(!strcmp(test_string.reversed().characters(), "FEDCBA"));
}

TEST_CASE(index_access)
Expand Down

0 comments on commit 09e89cc

Please sign in to comment.