diff options
| author | Po Lu | 2023-09-17 09:12:48 +0800 |
|---|---|---|
| committer | Po Lu | 2023-09-17 09:12:48 +0800 |
| commit | b2362cdcedfea5e9ee827c41bf158bc7000640a6 (patch) | |
| tree | a14aee8580542e4ace703bd84f2d38800a735a94 /src/androidmenu.c | |
| parent | 41a45373c1b7f19b06b3666a359331a40e494313 (diff) | |
| download | emacs-b2362cdcedfea5e9ee827c41bf158bc7000640a6.tar.gz emacs-b2362cdcedfea5e9ee827c41bf158bc7000640a6.zip | |
Speed up Android context menu generation
* src/androidmenu.c (android_menu_show, android_dialog_show):
Circumvent JNI dynamic method dispatch overhead.
Diffstat (limited to 'src/androidmenu.c')
| -rw-r--r-- | src/androidmenu.c | 77 |
1 files changed, 44 insertions, 33 deletions
diff --git a/src/androidmenu.c b/src/androidmenu.c index 94e3f646b44..70452b5dab0 100644 --- a/src/androidmenu.c +++ b/src/androidmenu.c | |||
| @@ -261,9 +261,11 @@ android_menu_show (struct frame *f, int x, int y, int menuflags, | |||
| 261 | struct android_menu_subprefix *subprefix_1; | 261 | struct android_menu_subprefix *subprefix_1; |
| 262 | bool checkmark; | 262 | bool checkmark; |
| 263 | unsigned int serial; | 263 | unsigned int serial; |
| 264 | JNIEnv *env; | ||
| 264 | 265 | ||
| 265 | count = SPECPDL_INDEX (); | 266 | count = SPECPDL_INDEX (); |
| 266 | serial = ++current_menu_serial; | 267 | serial = ++current_menu_serial; |
| 268 | env = android_java_env; | ||
| 267 | 269 | ||
| 268 | block_input (); | 270 | block_input (); |
| 269 | 271 | ||
| @@ -313,9 +315,10 @@ android_menu_show (struct frame *f, int x, int y, int menuflags, | |||
| 313 | context menu. */ | 315 | context menu. */ |
| 314 | store = current_context_menu; | 316 | store = current_context_menu; |
| 315 | current_context_menu | 317 | current_context_menu |
| 316 | = (*android_java_env)->CallObjectMethod (android_java_env, | 318 | = (*env)->CallNonvirtualObjectMethod (env, |
| 317 | current_context_menu, | 319 | current_context_menu, |
| 318 | menu_class.parent); | 320 | menu_class.class, |
| 321 | menu_class.parent); | ||
| 319 | android_exception_check (); | 322 | android_exception_check (); |
| 320 | 323 | ||
| 321 | if (store != context_menu) | 324 | if (store != context_menu) |
| @@ -403,11 +406,12 @@ android_menu_show (struct frame *f, int x, int y, int menuflags, | |||
| 403 | 406 | ||
| 404 | store = current_context_menu; | 407 | store = current_context_menu; |
| 405 | current_context_menu | 408 | current_context_menu |
| 406 | = (*android_java_env)->CallObjectMethod (android_java_env, | 409 | = (*env)->CallNonvirtualObjectMethod (env, |
| 407 | current_context_menu, | 410 | current_context_menu, |
| 408 | menu_class.add_submenu, | 411 | menu_class.class, |
| 409 | title_string, | 412 | menu_class.add_submenu, |
| 410 | help_string); | 413 | title_string, |
| 414 | help_string); | ||
| 411 | android_exception_check (); | 415 | android_exception_check (); |
| 412 | 416 | ||
| 413 | if (store != context_menu) | 417 | if (store != context_menu) |
| @@ -449,17 +453,18 @@ android_menu_show (struct frame *f, int x, int y, int menuflags, | |||
| 449 | checkmark = (EQ (type, QCtoggle) | 453 | checkmark = (EQ (type, QCtoggle) |
| 450 | || EQ (type, QCradio)); | 454 | || EQ (type, QCradio)); |
| 451 | 455 | ||
| 452 | (*android_java_env)->CallVoidMethod (android_java_env, | 456 | (*env)->CallNonvirtualVoidMethod (env, |
| 453 | current_context_menu, | 457 | current_context_menu, |
| 454 | menu_class.add_item, | 458 | menu_class.class, |
| 455 | (jint) item_id, | 459 | menu_class.add_item, |
| 456 | title_string, | 460 | (jint) item_id, |
| 457 | (jboolean) !NILP (enable), | 461 | title_string, |
| 458 | (jboolean) checkmark, | 462 | (jboolean) !NILP (enable), |
| 459 | (jboolean) !NILP (selected), | 463 | (jboolean) checkmark, |
| 460 | help_string, | 464 | (jboolean) !NILP (selected), |
| 461 | (jboolean) (EQ (type, | 465 | help_string, |
| 462 | QCradio))); | 466 | (jboolean) (EQ (type, |
| 467 | QCradio))); | ||
| 463 | android_exception_check (); | 468 | android_exception_check (); |
| 464 | 469 | ||
| 465 | if (title_string) | 470 | if (title_string) |
| @@ -479,12 +484,12 @@ android_menu_show (struct frame *f, int x, int y, int menuflags, | |||
| 479 | /* Now, display the context menu. */ | 484 | /* Now, display the context menu. */ |
| 480 | window = android_resolve_handle (FRAME_ANDROID_WINDOW (f), | 485 | window = android_resolve_handle (FRAME_ANDROID_WINDOW (f), |
| 481 | ANDROID_HANDLE_WINDOW); | 486 | ANDROID_HANDLE_WINDOW); |
| 482 | rc = (*android_java_env)->CallBooleanMethod (android_java_env, | 487 | rc = (*env)->CallNonvirtualBooleanMethod (env, context_menu, |
| 483 | context_menu, | 488 | menu_class.class, |
| 484 | menu_class.display, | 489 | menu_class.display, |
| 485 | window, (jint) x, | 490 | window, (jint) x, |
| 486 | (jint) y, | 491 | (jint) y, |
| 487 | (jint) serial); | 492 | (jint) serial); |
| 488 | android_exception_check (); | 493 | android_exception_check (); |
| 489 | 494 | ||
| 490 | if (!rc) | 495 | if (!rc) |
| @@ -652,6 +657,7 @@ android_dialog_show (struct frame *f, Lisp_Object title, | |||
| 652 | int id; | 657 | int id; |
| 653 | jmethodID method; | 658 | jmethodID method; |
| 654 | unsigned int serial; | 659 | unsigned int serial; |
| 660 | JNIEnv *env; | ||
| 655 | 661 | ||
| 656 | /* Generate a unique ID for events from this dialog box. */ | 662 | /* Generate a unique ID for events from this dialog box. */ |
| 657 | serial = ++current_menu_serial; | 663 | serial = ++current_menu_serial; |
| @@ -690,6 +696,11 @@ android_dialog_show (struct frame *f, Lisp_Object title, | |||
| 690 | ANDROID_DELETE_LOCAL_REF (java_header); | 696 | ANDROID_DELETE_LOCAL_REF (java_header); |
| 691 | ANDROID_DELETE_LOCAL_REF (java_title); | 697 | ANDROID_DELETE_LOCAL_REF (java_title); |
| 692 | 698 | ||
| 699 | /* Save the JNI environment pointer prior to constructing the | ||
| 700 | dialog, as typing (*android_java_env)->... gives rise to very | ||
| 701 | long lines. */ | ||
| 702 | env = android_java_env; | ||
| 703 | |||
| 693 | /* Create the buttons. */ | 704 | /* Create the buttons. */ |
| 694 | i = MENU_ITEMS_PANE_LENGTH; | 705 | i = MENU_ITEMS_PANE_LENGTH; |
| 695 | while (i < menu_items_used) | 706 | while (i < menu_items_used) |
| @@ -722,11 +733,11 @@ android_dialog_show (struct frame *f, Lisp_Object title, | |||
| 722 | 733 | ||
| 723 | /* Add the button. */ | 734 | /* Add the button. */ |
| 724 | temp = android_build_string (item_name); | 735 | temp = android_build_string (item_name); |
| 725 | (*android_java_env)->CallVoidMethod (android_java_env, | 736 | (*env)->CallNonvirtualVoidMethod (env, dialog, |
| 726 | dialog, | 737 | dialog_class.class, |
| 727 | dialog_class.add_button, | 738 | dialog_class.add_button, |
| 728 | temp, (jint) i, | 739 | temp, (jint) i, |
| 729 | (jboolean) NILP (enable)); | 740 | (jboolean) NILP (enable)); |
| 730 | android_exception_check (); | 741 | android_exception_check (); |
| 731 | ANDROID_DELETE_LOCAL_REF (temp); | 742 | ANDROID_DELETE_LOCAL_REF (temp); |
| 732 | i += MENU_ITEMS_ITEM_LENGTH; | 743 | i += MENU_ITEMS_ITEM_LENGTH; |
| @@ -734,9 +745,9 @@ android_dialog_show (struct frame *f, Lisp_Object title, | |||
| 734 | } | 745 | } |
| 735 | 746 | ||
| 736 | /* The dialog is now built. Run it. */ | 747 | /* The dialog is now built. Run it. */ |
| 737 | rc = (*android_java_env)->CallBooleanMethod (android_java_env, | 748 | rc = (*env)->CallNonvirtualBooleanMethod (env, dialog, |
| 738 | dialog, | 749 | dialog_class.class, |
| 739 | dialog_class.display); | 750 | dialog_class.display); |
| 740 | android_exception_check (); | 751 | android_exception_check (); |
| 741 | 752 | ||
| 742 | if (!rc) | 753 | if (!rc) |