summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston Sequoia <jeremyhu@apple.com>2021-02-18 09:41:30 -0800
committerJeremy Huddleston Sequoia <jeremyhu@apple.com>2021-02-18 22:32:14 -0800
commit39c0e1c0ab6a0a89a71f26446973c779ca7fd927 (patch)
tree17638334e78fbcf69964d1ba74b7cb423fda1919
parent87f8fe1f74f10faf0ffc84f03539799ad4c2465e (diff)
xquartz: Fold away array_with_strings_and_numbers and simplify with more modern Objective-C
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
-rw-r--r--hw/xquartz/X11Application.m50
1 files changed, 15 insertions, 35 deletions
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 1d281b9fe..b1757b846 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -901,48 +901,28 @@ cfarray_to_nsarray(CFArrayRef in)
@end
-static NSArray *
-array_with_strings_and_numbers(int nitems, const char **items,
- const char *numbers)
-{
- NSMutableArray *array, *subarray;
- NSString *string, *number;
- int i;
-
- array = [[[NSMutableArray alloc] initWithCapacity:nitems] autorelease];
-
- for (i = 0; i < nitems; i++) {
- subarray = [[NSMutableArray alloc] initWithCapacity:2];
-
- string = [[NSString alloc] initWithUTF8String:items[i]];
- [subarray addObject:string];
- [string release];
-
- if (numbers[i] != 0) {
- number = [[NSString alloc] initWithFormat:@"%d", numbers[i]];
- [subarray addObject:number];
- [number release];
- }
- else
- [subarray addObject:@""];
-
- [array addObject:subarray];
- [subarray release];
- }
-
- return array;
-}
-
void
X11ApplicationSetWindowMenu(int nitems, const char **items,
const char *shortcuts)
{
@autoreleasepool {
- NSArray *array = array_with_strings_and_numbers(nitems, items, shortcuts);
+ NSMutableArray <NSArray <NSString *> *> * const allMenuItems = [NSMutableArray array];
+
+ for (int i = 0; i < nitems; i++) {
+ NSMutableArray <NSString *> * const menuItem = [NSMutableArray array];
+ [menuItem addObject:@(items[i])];
+
+ if (shortcuts[i] == 0) {
+ [menuItem addObject:@""];
+ } else {
+ [menuItem addObject:[NSString stringWithFormat:@"%d", shortcuts[i]]];
+ }
+
+ [allMenuItems addObject:menuItem];
+ }
- /* Send the array of strings over to the appkit thread */
dispatch_async(dispatch_get_main_queue(), ^{
- [X11App set_window_menu:array];
+ [X11App set_window_menu:allMenuItems];
});
}
}