[sword-devel] Listkey loop over
Troy A. Griffitts
scribe at crosswire.org
Fri Feb 26 10:13:10 MST 2010
Dear Manfred, What I think you are getting at, is, given:
ListKey verses = VerseKey().ParseVerseList("Gen 1:1;4:5-8");
What is the difference between:
----------------------
verses.Persist(true);
mod.setKey(verses);
for (mod == TOP; !mod.Error(); mod++) {
cout << mod.RenderText();
}
======================
for (verses = TOP; !verses.Error(); verses++) {
mod.setKey(verses);
cout << mod.RenderText();
}
++++++++++++++++++++++
and I think you'll find not too much. I believe the reason you were
seeing undesired results and a slower speed was because in your second
example, you were initializing mod to Gen.1.1 and incrementing until you
reached Gen.4.8, Your first example should iterate 5 verses. Your
second example should iterate over a thousand verses. I believe the two
examples I've listed above compare apples to apples when it comes to
persistent vs. non-persistent keys, and both should only iterated the 5
verses in your parse string.
Hope this helps.
Troy
Manfred Bergmann wrote:
> 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
>
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above
More information about the sword-devel
mailing list