Merge pull request #45234 from madmiraal/rename-phashtranslation

Rename PHashTranslation to OptimizedTranslation
This commit is contained in:
Rémi Verschelde 2021-03-23 00:12:12 +01:00 committed by GitHub
commit 6a84ade316
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 29 deletions

View file

@ -68,7 +68,7 @@
#include "core/object/class_db.h"
#include "core/object/undo_redo.h"
#include "core/os/main_loop.h"
#include "core/string/compressed_translation.h"
#include "core/string/optimized_translation.h"
#include "core/string/translation.h"
static Ref<ResourceFormatSaverBinary> resource_saver_binary;
@ -183,7 +183,7 @@ void register_core_types() {
ClassDB::register_class<MultiplayerAPI>();
ClassDB::register_class<MainLoop>();
ClassDB::register_class<Translation>();
ClassDB::register_class<PHashTranslation>();
ClassDB::register_class<OptimizedTranslation>();
ClassDB::register_class<UndoRedo>();
ClassDB::register_class<HTTPClient>();
ClassDB::register_class<TriangleMesh>();

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* compressed_translation.cpp */
/* optimized_translation.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "compressed_translation.h"
#include "optimized_translation.h"
#include "core/templates/pair.h"
@ -36,13 +36,13 @@ extern "C" {
#include "thirdparty/misc/smaz.h"
}
struct _PHashTranslationCmp {
struct CompressedString {
int orig_len;
CharString compressed;
int offset;
};
void PHashTranslation::generate(const Ref<Translation> &p_from) {
void OptimizedTranslation::generate(const Ref<Translation> &p_from) {
// This method compresses a Translation instance.
// Right now, it doesn't handle context or plurals, so Translation subclasses using plurals or context (i.e TranslationPO) shouldn't be compressed.
#ifdef TOOLS_ENABLED
@ -54,7 +54,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
Vector<Vector<Pair<int, CharString>>> buckets;
Vector<Map<uint32_t, int>> table;
Vector<uint32_t> hfunc_table;
Vector<_PHashTranslationCmp> compressed;
Vector<CompressedString> compressed;
table.resize(size);
hfunc_table.resize(size);
@ -76,7 +76,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
//compress string
CharString src_s = p_from->get_message(E->get()).operator String().utf8();
_PHashTranslationCmp ps;
CompressedString ps;
ps.orig_len = src_s.size();
ps.offset = total_compression_size;
@ -182,7 +182,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
#endif
}
bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) {
bool OptimizedTranslation::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name.operator String();
if (name == "hash_table") {
hash_table = p_value;
@ -199,7 +199,7 @@ bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) {
return true;
}
bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const {
bool OptimizedTranslation::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name.operator String();
if (name == "hash_table") {
r_ret = hash_table;
@ -214,8 +214,8 @@ bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const {
return true;
}
StringName PHashTranslation::get_message(const StringName &p_src_text, const StringName &p_context) const {
// p_context passed in is ignore. The use of context is not yet supported in PHashTranslation.
StringName OptimizedTranslation::get_message(const StringName &p_src_text, const StringName &p_context) const {
// p_context passed in is ignore. The use of context is not yet supported in OptimizedTranslation.
int htsize = hash_table.size();
@ -271,18 +271,18 @@ StringName PHashTranslation::get_message(const StringName &p_src_text, const Str
}
}
StringName PHashTranslation::get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context) const {
// The use of plurals translation is not yet supported in PHashTranslation.
StringName OptimizedTranslation::get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context) const {
// The use of plurals translation is not yet supported in OptimizedTranslation.
return get_message(p_src_text, p_context);
}
void PHashTranslation::_get_property_list(List<PropertyInfo> *p_list) const {
void OptimizedTranslation::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "hash_table"));
p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "bucket_table"));
p_list->push_back(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "strings"));
p_list->push_back(PropertyInfo(Variant::OBJECT, "load_from", PROPERTY_HINT_RESOURCE_TYPE, "Translation", PROPERTY_USAGE_EDITOR));
}
void PHashTranslation::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate", "from"), &PHashTranslation::generate);
void OptimizedTranslation::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate", "from"), &OptimizedTranslation::generate);
}

View file

@ -1,5 +1,5 @@
/*************************************************************************/
/* compressed_translation.h */
/* optimized_translation.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -28,13 +28,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef COMPRESSED_TRANSLATION_H
#define COMPRESSED_TRANSLATION_H
#ifndef OPTIMIZED_TRANSLATION_H
#define OPTIMIZED_TRANSLATION_H
#include "core/string/translation.h"
class PHashTranslation : public Translation {
GDCLASS(PHashTranslation, Translation);
class OptimizedTranslation : public Translation {
GDCLASS(OptimizedTranslation, Translation);
//this translation uses a sort of modified perfect hash algorithm
//it requires hashing strings twice and then does a binary search,
@ -83,7 +83,7 @@ public:
virtual StringName get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context = "") const override;
void generate(const Ref<Translation> &p_from);
PHashTranslation() {}
OptimizedTranslation() {}
};
#endif // COMPRESSED_TRANSLATION_H
#endif // OPTIMIZED_TRANSLATION_H

View file

@ -275,7 +275,7 @@ void TranslationPO::erase_message(const StringName &p_src_text, const StringName
}
void TranslationPO::get_message_list(List<StringName> *r_messages) const {
// PHashTranslation uses this function to get the list of msgid.
// OptimizedTranslation uses this function to get the list of msgid.
// Return all the keys of translation_map under "" context.
List<StringName> context_l;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="PHashTranslation" inherits="Translation" version="4.0">
<class name="OptimizedTranslation" inherits="Translation" version="4.0">
<brief_description>
Optimized translation.
</brief_description>

View file

@ -32,7 +32,7 @@
#include "core/io/resource_saver.h"
#include "core/os/file_access.h"
#include "core/string/compressed_translation.h"
#include "core/string/optimized_translation.h"
#include "core/string/translation.h"
String ResourceImporterCSVTranslation::get_importer_name() const {
@ -126,7 +126,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const
Ref<Translation> xlt = translations[i];
if (compress) {
Ref<PHashTranslation> cxl = memnew(PHashTranslation);
Ref<OptimizedTranslation> cxl = memnew(OptimizedTranslation);
cxl->generate(xlt);
xlt = cxl;
}

View file

@ -37,7 +37,7 @@
#include "core/os/dir_access.h"
#include "core/os/file_access.h"
#include "core/os/os.h"
#include "core/string/compressed_translation.h"
#include "core/string/optimized_translation.h"
#include "editor_data.h"
#include "editor_node.h"
#include "editor_scale.h"