[sword-devel] Listkey loop over

Manfred Bergmann manfred.bergmann at me.com
Fri Feb 26 09:09:16 MST 2010


Hi.

Again a SWORD API question.
I'm trying to optimise memory usage and speed issues.
At the moment I believe the API or better SWModule SWKey usage in MacSword is not as good as it could be.

Now while improving that I came across one or two questions.
First the following code (all code is in Objective-C syntax but is almost an equivalent to the C++ API):

---------------
- (void)testLoopWithModulePosWithDiverseReference {
    SwordListKey *lk = [SwordListKey listKeyWithRef:@"gen 1:1;4:5-8" v11n:[mod versification]];
    [lk setPersist:YES];
    [mod setKey:lk];
    NSString *ref = nil;
    NSString *rendered = nil;
    while(![mod error]) {
        ref = [lk keyText];
        rendered = [mod renderedText];
        NSLog(@"%@:%@", ref, rendered);
        [mod incKeyPosition];
    }
}
---------------
This code works and is pretty fast.
The output are only verses as in the reference. That's how it should be. The module only keeps a reference to the key.


This example:
---------------
- (void)testLoopWithModulePosNoPersistWithDiverseReference {
    SwordListKey *lk = [SwordListKey listKeyWithRef:@"gen 1:1;4:5-8" v11n:[mod versification]];
    [lk setPosition:BOTTOM];
    SwordVerseKey *bot = [SwordVerseKey verseKeyWithRef:[lk keyText] v11n:[mod versification]];
    [lk setPosition:TOP];

    [lk setPersist:NO];
    [mod setKey:lk];
    NSString *ref = nil;
    NSString *rendered = nil;
    while(![mod error] && ([(SwordVerseKey *)[mod getKey] index] <= [bot index])) {
        ref = [[mod getKey] keyText];
        rendered = [mod renderedText];
        NSLog(@"%@:%@", ref, rendered);
        [mod incKeyPosition];
    }
}
---------------
This version however renders all verses from gen 1:1 to gen 4:8.
The only difference is that the module keeps it's own copy of the key.
The boundary check "![mod error]" doesn't work here so I added the index check mainly because I didn't know otherwise.

How does this loop work with a none persistent key?



Thanks,
Manfred



More information about the sword-devel mailing list