Replace a dangerous function with the convenience function callers actually want.
Change-Id: Ic22dc4db36850507760a917033c254b88749b657
diff --git a/src/class_linker_test.cc b/src/class_linker_test.cc
index 21c576e..fd7fecf 100644
--- a/src/class_linker_test.cc
+++ b/src/class_linker_test.cc
@@ -442,7 +442,7 @@
Field* s8 = statics->GetStaticField(8);
EXPECT_EQ('L', s8->GetType());
// EXPECT_TRUE(down_cast<String*>(s8->GetObject())->Equals("android")); // TODO: uncomment this
- s8->SetObject(String::AllocFromAscii("robot"));
+ s8->SetObject(String::AllocFromModifiedUtf8("robot"));
Field* s9 = statics->GetStaticField(9);
EXPECT_EQ('[', s9->GetType());
diff --git a/src/intern_table_test.cc b/src/intern_table_test.cc
index e6bb611..662a8b6 100644
--- a/src/intern_table_test.cc
+++ b/src/intern_table_test.cc
@@ -15,7 +15,7 @@
InternTable intern_table;
String* foo_1 = intern_table.Intern(3, "foo");
String* foo_2 = intern_table.Intern(3, "foo");
- String* foo_3 = String::AllocFromAscii("foo");
+ String* foo_3 = String::AllocFromModifiedUtf8("foo");
String* bar = intern_table.Intern(3, "bar");
EXPECT_TRUE(foo_1->Equals("foo"));
EXPECT_TRUE(foo_2->Equals("foo"));
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 586b541..fd66d73 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -1741,8 +1741,7 @@
if (utf == NULL) {
return NULL;
}
- size_t char_count = String::ModifiedUtf8Len(utf);
- String* result = String::AllocFromModifiedUtf8(char_count, utf);
+ String* result = String::AllocFromModifiedUtf8(utf);
return AddLocalReference<jstring>(ts, result);
}
diff --git a/src/object.h b/src/object.h
index 1789ec8..2384fde 100644
--- a/src/object.h
+++ b/src/object.h
@@ -1301,28 +1301,18 @@
return string;
}
- static String* AllocFromModifiedUtf8(Class* java_lang_String,
- int32_t utf16_length,
- const char* utf8_data_in) {
- String* string = Alloc(java_lang_String, utf16_length);
- uint16_t* utf16_data_out = string->array_->GetData();
- ConvertModifiedUtf8ToUtf16(utf16_data_out, utf8_data_in);
- string->ComputeHashCode();
- return string;
- }
-
- // Creates a String of the given ASCII characters. It is an error to call this
- // using non-ASCII characters as this function assumes one char per byte.
- static String* AllocFromAscii(const char* ascii_data_in) {
- return AllocFromModifiedUtf8(GetJavaLangString(),
- strlen(ascii_data_in),
- ascii_data_in);
+ static String* AllocFromModifiedUtf8(const char* utf) {
+ size_t char_count = ModifiedUtf8Len(utf);
+ return AllocFromModifiedUtf8(char_count, utf);
}
static String* AllocFromModifiedUtf8(int32_t utf16_length,
const char* utf8_data_in) {
- return AllocFromModifiedUtf8(GetJavaLangString(),
- utf16_length, utf8_data_in);
+ String* string = Alloc(GetJavaLangString(), utf16_length);
+ uint16_t* utf16_data_out = string->array_->GetData();
+ ConvertModifiedUtf8ToUtf16(utf16_data_out, utf8_data_in);
+ string->ComputeHashCode();
+ return string;
}
static void InitClasses(Class* java_lang_String);
diff --git a/src/object_test.cc b/src/object_test.cc
index 8f9bed6..3f5333b 100644
--- a/src/object_test.cc
+++ b/src/object_test.cc
@@ -164,7 +164,7 @@
}
TEST_F(ObjectTest, StringEqualsUtf8) {
- String* string = String::AllocFromAscii("android");
+ String* string = String::AllocFromModifiedUtf8("android");
EXPECT_TRUE(string->Equals("android"));
EXPECT_FALSE(string->Equals("Android"));
EXPECT_FALSE(string->Equals("ANDROID"));
@@ -172,21 +172,21 @@
EXPECT_FALSE(string->Equals("and"));
EXPECT_FALSE(string->Equals("androids"));
- String* empty = String::AllocFromAscii("");
+ String* empty = String::AllocFromModifiedUtf8("");
EXPECT_TRUE(empty->Equals(""));
EXPECT_FALSE(empty->Equals("a"));
}
TEST_F(ObjectTest, StringEquals) {
- String* string = String::AllocFromAscii("android");
- EXPECT_TRUE(string->Equals(String::AllocFromAscii("android")));
+ String* string = String::AllocFromModifiedUtf8("android");
+ EXPECT_TRUE(string->Equals(String::AllocFromModifiedUtf8("android")));
EXPECT_FALSE(string->Equals("Android"));
EXPECT_FALSE(string->Equals("ANDROID"));
EXPECT_FALSE(string->Equals(""));
EXPECT_FALSE(string->Equals("and"));
EXPECT_FALSE(string->Equals("androids"));
- String* empty = String::AllocFromAscii("");
+ String* empty = String::AllocFromModifiedUtf8("");
EXPECT_TRUE(empty->Equals(""));
EXPECT_FALSE(empty->Equals("a"));
}
@@ -237,9 +237,9 @@
TEST_F(ObjectTest, StringHashCode) {
- EXPECT_EQ(0U, String::AllocFromAscii("")->GetHashCode());
- EXPECT_EQ(65U, String::AllocFromAscii("A")->GetHashCode());
- EXPECT_EQ(64578U, String::AllocFromAscii("ABC")->GetHashCode());
+ EXPECT_EQ(0U, String::AllocFromModifiedUtf8("")->GetHashCode());
+ EXPECT_EQ(65U, String::AllocFromModifiedUtf8("A")->GetHashCode());
+ EXPECT_EQ(64578U, String::AllocFromModifiedUtf8("ABC")->GetHashCode());
}
TEST_F(ObjectTest, InstanceOf) {
diff --git a/src/reference_table_test.cc b/src/reference_table_test.cc
index 4728cb0..1f065e6 100644
--- a/src/reference_table_test.cc
+++ b/src/reference_table_test.cc
@@ -12,7 +12,7 @@
};
TEST_F(ReferenceTableTest, Basics) {
- Object* o1 = String::AllocFromModifiedUtf8(0, "hello");
+ Object* o1 = String::AllocFromModifiedUtf8("hello");
Object* o2 = ShortArray::Alloc(0);
// TODO: rewrite Dump to take a std::ostream& so we can test it better.
diff --git a/src/thread.cc b/src/thread.cc
index eb7a4f7..dd333d7 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -145,8 +145,7 @@
Object* exception = exception_class->NewInstance();
CHECK(exception != NULL);
- size_t char_count = String::ModifiedUtf8Len(msg);
- String* java_msg = String::AllocFromModifiedUtf8(char_count, msg);
+ String* java_msg = String::AllocFromModifiedUtf8(msg);
CHECK(java_msg != NULL);
// TODO: what if there's already a pending exception?
diff --git a/src/utils_test.cc b/src/utils_test.cc
index dd411c2..8f2b3ba 100644
--- a/src/utils_test.cc
+++ b/src/utils_test.cc
@@ -54,7 +54,7 @@
TEST_F(UtilsTest, PrettyType) {
EXPECT_EQ("null", PrettyType(NULL));
- String* s = String::AllocFromModifiedUtf8(0, "");
+ String* s = String::AllocFromModifiedUtf8("");
EXPECT_EQ("java.lang.String", PrettyType(s));
ShortArray* a = ShortArray::Alloc(2);