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

Commit 43dfda59 authored by Shuangxi Xiang's avatar Shuangxi Xiang Committed by Cherrypicker Worker
Browse files

Code style optimization in setArgv0



Here, 15 is equal to the length of the kernel task name minus 1. Replacing 15 with a constant type improves readability, maintainability, and robustness. Although it does not directly affect performance, it can significantly reduce future maintenance costs and meet code specification requirements.

Signed-off-by: default avatarxiangshuangxi <xiangshuangxi@xiaomi.com>
(cherry picked from https://android-review.googlesource.com/q/commit:c724356019eaa1b62c74a1515e046c0fce1ed0b5)
Merged-In: I0df041c08f216fa89e987a8178d7933dca274a2a
Change-Id: I0df041c08f216fa89e987a8178d7933dca274a2a
parent 40acc9a7
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -264,6 +264,9 @@ static const char* kLockProfThresholdRuntimeOption = "-Xlockprofthreshold:0";


static AndroidRuntime* gCurRuntime = NULL;
static AndroidRuntime* gCurRuntime = NULL;


//The kernel's TASK_COMM_LEN minus one for the terminating NUL == 15.
static constexpr int THREAD_NAME_TRUNCATION_LEN = 15;

/*
/*
 * Code written in the Java Programming Language calls here from main().
 * Code written in the Java Programming Language calls here from main().
 */
 */
@@ -342,13 +345,12 @@ AndroidRuntime::~AndroidRuntime()


void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
    // Set the kernel's task name, for as much of the name as we can fit.
    // Set the kernel's task name, for as much of the name as we can fit.
    // The kernel's TASK_COMM_LEN minus one for the terminating NUL == 15.
    if (setProcName) {
    if (setProcName) {
        int len = strlen(argv0);
        int len = strlen(argv0);
        if (len < 15) {
        if (len < THREAD_NAME_TRUNCATION_LEN) {
            pthread_setname_np(pthread_self(), argv0);
            pthread_setname_np(pthread_self(), argv0);
        } else {
        } else {
            pthread_setname_np(pthread_self(), argv0 + len - 15);
            pthread_setname_np(pthread_self(), argv0 + len - THREAD_NAME_TRUNCATION_LEN);
        }
        }
    }
    }