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

Commit 23daf265 authored by Muhammad Qureshi's avatar Muhammad Qureshi
Browse files

Only send reset state annotation when needed

Only send reset state annotation when reset state occurs.

Bug: 151776731
Test: m libstatslog

Change-Id: I6f6b4d784d3741c0059085421565eba81db5527c
parent c6c38632
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ static void write_annotations(FILE* out, int argIndex,
    for (const shared_ptr<AtomDecl>& atomDecl : atomDeclSet) {
        fprintf(out, "        if (code == %d) {\n", atomDecl->code);
        const AnnotationSet& annotations = atomDecl->fieldNumberToAnnotations.at(argIndex);
        int resetState = -1;
        int defaultState = -1;
        for (const shared_ptr<Annotation>& annotation : annotations) {
            // TODO(b/151786433): Write atom constant name instead of atom id literal.
            switch (annotation->type) {
@@ -58,8 +60,14 @@ static void write_annotations(FILE* out, int argIndex,
                case ANNOTATION_TYPE_INT:
                    // TODO(b/151786433): Write annotation constant name instead of
                    // annotation id literal.
                    if (ANNOTATION_ID_RESET_STATE == annotation->annotationId) {
                        resetState = annotation->value.intValue;
                    } else if (ANNOTATION_ID_DEFAULT_STATE == annotation->annotationId) {
                        defaultState = annotation->value.intValue;
                    } else {
                        fprintf(out, "            builder.addIntAnnotation((byte) %d, %d);\n",
                                annotation->annotationId, annotation->value.intValue);
                    }
                    break;
                case ANNOTATION_TYPE_BOOL:
                    // TODO(b/151786433): Write annotation constant name instead of
@@ -72,6 +80,12 @@ static void write_annotations(FILE* out, int argIndex,
                    break;
            }
        }
        if (defaultState != -1 && resetState != -1) {
            fprintf(out, "            if (arg%d == %d) {\n", argIndex, resetState);
            fprintf(out, "                builder.addIntAnnotation((byte) %d, %d);\n",
                    ANNOTATION_ID_RESET_STATE, defaultState);
            fprintf(out, "            }\n");
        }
        fprintf(out, "        }\n");
    }
}
+17 −3
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ static void write_annotations(FILE* out, int argIndex,
    for (const shared_ptr<AtomDecl>& atomDecl : atomDeclSet) {
        fprintf(out, "    if (code == %d) {\n", atomDecl->code);
        const AnnotationSet& annotations = atomDecl->fieldNumberToAnnotations.at(argIndex);
        int resetState = -1;
        int defaultState = -1;
        for (const shared_ptr<Annotation>& annotation : annotations) {
            // TODO(b/151786433): Write atom constant name instead of atom id literal.
            switch (annotation->type) {
@@ -41,9 +43,15 @@ static void write_annotations(FILE* out, int argIndex,
                case ANNOTATION_TYPE_INT:
                    // TODO(b/151786433): Write annotation constant name instead of
                    // annotation id literal.
                    fprintf(out, "        %saddInt32Annotation(%s%d, %d);\n", methodPrefix.c_str(),
                            methodSuffix.c_str(), annotation->annotationId,
                            annotation->value.intValue);
                    if (ANNOTATION_ID_RESET_STATE == annotation->annotationId) {
                        resetState = annotation->value.intValue;
                    } else if (ANNOTATION_ID_DEFAULT_STATE == annotation->annotationId) {
                        defaultState = annotation->value.intValue;
                    } else {
                        fprintf(out, "        %saddInt32Annotation(%s%d, %d);\n",
                                methodPrefix.c_str(), methodSuffix.c_str(),
                                annotation->annotationId, annotation->value.intValue);
                    }
                    break;
                case ANNOTATION_TYPE_BOOL:
                    // TODO(b/151786433): Write annotation constant name instead of
@@ -56,6 +64,12 @@ static void write_annotations(FILE* out, int argIndex,
                    break;
            }
        }
        if (defaultState != -1 && resetState != -1) {
            fprintf(out, "        if (arg%d == %d) {\n", argIndex, resetState);
            fprintf(out, "            %saddInt32Annotation(%s%d, %d);\n", methodPrefix.c_str(),
                    methodSuffix.c_str(), ANNOTATION_ID_RESET_STATE, defaultState);
            fprintf(out, "        }\n");
        }
        fprintf(out, "    }\n");
    }
}