Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 54035065 authored by Ken Wakasa's avatar Ken Wakasa Committed by Android (Google) Code Review
Browse files

Merge "A couple of cleanups. Remove unnecessary casts." into jb-mr1-dev

parents a0cd0584 34710b03
Loading
Loading
Loading
Loading
+16 −17
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <sys/mman.h>
#else // USE_MMAP_FOR_DICTIONARY
#include <cstdlib>
#include <cstdio> // for fopen() etc.
#endif // USE_MMAP_FOR_DICTIONARY

#include "binary_format.h"
@@ -40,7 +41,7 @@ namespace latinime {

class ProximityInfo;

static void releaseDictBuf(void *dictBuf, const size_t length, int fd);
static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd);

static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
        jstring sourceDir, jlong dictOffset, jlong dictSize,
@@ -75,7 +76,7 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
        AKLOGE("DICT: Can't mmap dictionary. errno=%d", errno);
        return 0;
    }
    dictBuf = reinterpret_cast<void *>(reinterpret_cast<char *>(dictBuf) + adjust);
    dictBuf = static_cast<char *>(dictBuf) + adjust;
#else // USE_MMAP_FOR_DICTIONARY
    /* malloc version */
    FILE *file = 0;
@@ -111,10 +112,10 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
    }
    Dictionary *dictionary = 0;
    if (BinaryFormat::UNKNOWN_FORMAT
            == BinaryFormat::detectFormat(reinterpret_cast<uint8_t *>(dictBuf))) {
            == BinaryFormat::detectFormat(static_cast<uint8_t *>(dictBuf))) {
        AKLOGE("DICT: dictionary format is unknown, bad magic number");
#ifdef USE_MMAP_FOR_DICTIONARY
        releaseDictBuf(reinterpret_cast<char *>(dictBuf) - adjust, adjDictSize, fd);
        releaseDictBuf(static_cast<const char *>(dictBuf) - adjust, adjDictSize, fd);
#else // USE_MMAP_FOR_DICTIONARY
        releaseDictBuf(dictBuf, 0, 0);
#endif // USE_MMAP_FOR_DICTIONARY
@@ -249,12 +250,10 @@ static jint latinime_BinaryDictionary_editDistance(JNIEnv *env, jobject object,
static void latinime_BinaryDictionary_close(JNIEnv *env, jobject object, jlong dict) {
    Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
    if (!dictionary) return;
    void *dictBuf = dictionary->getDict();
    const void *dictBuf = dictionary->getDict();
    if (!dictBuf) return;
#ifdef USE_MMAP_FOR_DICTIONARY
    releaseDictBuf(
            reinterpret_cast<void *>(
                    reinterpret_cast<char *>(dictBuf) - dictionary->getDictBufAdjust()),
    releaseDictBuf(static_cast<const char *>(dictBuf) - dictionary->getDictBufAdjust(),
            dictionary->getDictSize() + dictionary->getDictBufAdjust(), dictionary->getMmapFd());
#else // USE_MMAP_FOR_DICTIONARY
    releaseDictBuf(dictBuf, 0, 0);
@@ -262,9 +261,9 @@ static void latinime_BinaryDictionary_close(JNIEnv *env, jobject object, jlong d
    delete dictionary;
}

static void releaseDictBuf(void *dictBuf, const size_t length, int fd) {
static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd) {
#ifdef USE_MMAP_FOR_DICTIONARY
    int ret = munmap(dictBuf, length);
    int ret = munmap(const_cast<void *>(dictBuf), length);
    if (ret != 0) {
        AKLOGE("DICT: Failure in munmap. ret=%d errno=%d", ret, errno);
    }
@@ -273,7 +272,7 @@ static void releaseDictBuf(void *dictBuf, const size_t length, int fd) {
        AKLOGE("DICT: Failure in close. ret=%d errno=%d", ret, errno);
    }
#else // USE_MMAP_FOR_DICTIONARY
    free(dictBuf);
    free(const_cast<void *>(dictBuf));
#endif // USE_MMAP_FOR_DICTIONARY
}

+6 −6
Original line number Diff line number Diff line
@@ -55,11 +55,11 @@ class Dictionary {

    int getFrequency(const int32_t *word, int length) const;
    bool isValidBigram(const int32_t *word1, int length1, const int32_t *word2, int length2) const;
    void *getDict() const { // required to release dictionary buffer
        return reinterpret_cast<void *>(const_cast<unsigned char *>(mDict));
    const uint8_t *getDict() const { // required to release dictionary buffer
        return mDict;
    }
    void *getOffsetDict() const {
        return reinterpret_cast<void *>(const_cast<unsigned char *>(mOffsetDict));
    const uint8_t *getOffsetDict() const {
        return mOffsetDict;
    }
    int getDictSize() const { return mDictSize; }
    int getMmapFd() const { return mMmapFd; }
@@ -72,8 +72,8 @@ class Dictionary {

 private:
    DISALLOW_IMPLICIT_CONSTRUCTORS(Dictionary);
    const unsigned char *mDict;
    const unsigned char *mOffsetDict;
    const uint8_t *mDict;
    const uint8_t *mOffsetDict;

    // Used only for the mmap version of dictionary loading, but we use these as dummy variables
    // also for the malloc version.
+1 −1

File changed.

Contains only whitespace changes.

+1 −1

File changed.

Contains only whitespace changes.

+1 −1

File changed.

Contains only whitespace changes.

+3 −3

File changed.

Contains only whitespace changes.

Loading