From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,789b3fa522bdcc2a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-01 19:17:01 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!out.nntp.be!propagator2-sterling!news-in.nuthinbutnews.com!cyclone1.gnilink.net!wn14feed!wn13feed!wn12feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc03.POSTED!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: <1049198066.356477@edh3> Subject: Re: Optimising string handling in application X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: NNTP-Posting-Host: 12.211.13.75 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc03 1049253420 12.211.13.75 (Wed, 02 Apr 2003 03:17:00 GMT) NNTP-Posting-Date: Wed, 02 Apr 2003 03:17:00 GMT Organization: AT&T Broadband Date: Wed, 02 Apr 2003 03:17:00 GMT Xref: archiver1.google.com comp.lang.ada:35875 Date: 2003-04-02T03:17:00+00:00 List-Id: A few suggestions: Instead of looping to find the end of the string, use the "Index" function from Ada.Strings.Fixed on a slice of the original string instead of your own loop. Something like: Delete_Stop := Ada.Strings.Fixed.Index( Source => Msg( Delete_Start .. Msg_Length ) ... If Delete_Stop = 0 Then Delete_Stop := Msg_Length; Else Delete_stop := Delete_Stop - 1; End If; Then use Ada.Strings.Fixed.Replace_Slice to replace the string between Delete_Start and Delete_Stop. If I were writing the code I would probably use Ada.Strings.Bounded instead of passing around fixed sized strings separate from the length, then use the corresponding Index and Replace_Slice functions from Ada.Strings.Bounded. Using bounded strings has the advantage that the library does the work of maintaining string lengths for you. That is: Package Callsign_String_Package is new Ada.Strings.Bounded.Generic_Bounded_Length( C_Max_Msg_Size ); subtype T_Msg_Data_Str is Callsign_String_Package.Bounded_String; etc Steve (The Duck) BTW: I find your naming conventions awkward... personal preferance. "Frode Tenneboe" wrote in message news:1049198066.356477@edh3... > > I have a small-ish procedure which only purpose is to take a > formatted string (see example) and replace the callsign(s) > inside with another. > > The strings look like: > > "ME000=F012;ME001=AAA,BBB,CCC;ME002=FOO...." > > I would like to replace "ME001=AAA,BBB,CCC" with "ME001=AAA". The > procedure below does just that. However, looking at the code, I don't > like the lumpyness (in lack of a better word). There must be a > more elegant way of doing this? Any ideas? > [snip] > > -Frode > > -- > ^ Frode Tenneb� | email: Frode.Tennebo@eto.ericsson.se ^ > | Ericsson AS., N-1788 Halden | Phone: +47 67 25 09 39 | > | with Standard.Disclaimer; use Standard.Disclaimer; |