Re: Converting char(s) into String




"Oliver Wong" <owong@xxxxxxxxxxxxxx> wrote in message
news:7xfjg.29561$771.11011@xxxxxxxxxxx
"Oliver Wong" <owong@xxxxxxxxxxxxxx> wrote in message
news:DCkig.27254$771.10711@xxxxxxxxxxx
Why would even a dumb compiler
produce worse code?

Perhaps because it depends on knowledge of the API. It might be
occasionally be desirable to run a Java program without any of Sun's API
available. If the compiler produced code using StringBuffer
[obviously, I meant String instead of StringBuffer here]
, the JVM might report a "StringBuffer class not found", despite the fact
that the original source code never mentions StringBuffer.

I mentioned this mainly because in this competition I had entered for
writing an optimizing Java compiler, I had taken advantage of the fact
that I knew the behaviour of the StringBuffer class to replace certain
calls with others. If I recall correctly, it was something like changing
this:

<pseudo bytecode>
invoke 0 parameter constructor of StringBuffer.
dup
push "Foo"
invoke 1 parameter append method.
dup
push "Bar"
invoke 1 parameter append method.
invoke 0 parameter toString
</pseudo bytecode>

to this:

<pseudo bytecode>
push "Foo"
invoke 1 parameter constructor of StringBuffer.
dup
push "Bar"
invoke 1 parameter append method.
invoke 0 parameter toString
</pseudo bytecode>

and the judges said I shouldn't have relied on information on the
semantics/behaviour of the API,

Uh-huh. It's OK to use one constructor and the append method, but using a
different constructor is cheating. What had they been smoking?

but they let it slide for this competition anyway.


.



Relevant Pages

  • Re: Converting char(s) into String
    ... It might be occasionally be desirable to run a Java program without any of Sun's API available. ... If the compiler produced code using StringBuffer ... invoke 0 parameter constructor of StringBuffer. ... invoke 1 parameter append method. ...
    (comp.lang.java.programmer)
  • Re: Converting char(s) into String
    ... It might be occasionally be desirable to run a Java program without any of Sun's API available. ... If the compiler produced code using StringBuffer ... invoke 0 parameter constructor of StringBuffer. ... invoke 1 parameter append method. ...
    (comp.lang.java.programmer)
  • Re: Learning Assembly with an HLL
    ... unavoidable API stuff. ... it more difficult to comprehend why you would recommend INVOKE. ... bytes and that the 32 bytes at top of stack must be available ... If the assembler doesn't know where the scratch space in the ...
    (comp.lang.asm.x86)
  • Re: Is MASM32 an evil Microsoft plot? (Part 2)
    ... push offset titletxt ... invoke MessageBox,hWnd,ADDR TxtMsg,ADDRTtlTxt,MB_OK ... MASM code through the most powerful assembler available in 32 bit ... and API call is just that, ...
    (alt.lang.asm)
  • absolute address
    ... The general solution is to use the ShellExecuteAPI with the ... "print" verb to invoke the registered application to print it. ...
    (microsoft.public.dotnet.languages.vc)